Mam jednak mały problem jeśli chodzi o relacje. Mam dwie tabele
[SQL] pobierz, plaintext
CREATE TABLE `to_dos` (
`id` bigint(20) UNSIGNED NOT NULL,
`todos_title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`todos_description` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`todos_nr_case` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`todos_status` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`todos_start` timestamp NOT NULL DEFAULT current_timestamp(),
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`todos_priority` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
CREATE TABLE `to_dos_processes` (
`id` bigint(20) UNSIGNED NOT NULL,
`todos_processes_title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`todos_processes_description` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`todos_processes_date` timestamp NOT NULL DEFAULT current_timestamp(),
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`todos_id` int(11) NOT NULL,
`todos_todo_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
[SQL] pobierz, plaintext
Stworzyłem więc migrację, ale coś namieszałem bo nie chce się ta migracja wykonać:
[PHP] pobierz, plaintext
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddRelationTodoToTodoprocesses extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('to_dos_processes', function (Blueprint $table) {;
$table->foreign('todos_todo_id')->references('id')->on('to_dos');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}
[PHP] pobierz, plaintext
SQLSTATE[HY000]: General error: 1005 Can't create table `asystent`.`to_dos_processes` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `to_dos_processes` add constraint `to_dos_processes_todos_todo_id_foreign` foreign key (`todos_todo_id`) references `to_dos` (`id`))
Kombinuję już z tym tematem trochę czasu ale cały czas mam problem.