Ich habe folgende Migration:Laravel Migrationsproblem: Tabelle Selbst Beziehung
Schema::create('tags', function (Blueprint $table) {
$table->increments('id')->unsigned()->index();
$table->string('name',30);
$table->integer('parent_id')->nullable();
$table->string('image_url');
$table->string('image_id',50);
$table->timestamps();
$table->foreign('parent_id')
->references('id')->on('tags')
->onDelete('cascade');
});
Das folgende Problem aufkommt:
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alte
r table `tags` add constraint `tags_parent_id_foreign` foreign key (`parent_id`) references `tags` (`id`) on delete cascade)
Alles ist gut. Ich habe viel geprüft, aber nicht funktioniert.
Die folgende Frage funktioniert nicht für mich. Ich weiß nicht warum, diese Frage geht nicht auf meine Probleme ein.
Mögliches Duplikat von [Laravel-Migrationsselbstverweis-Fremdschlüsselproblem] (http://stackoverflow.com/questions/18427391/laravel-migration-self-referencing-foreign-key-issue) – Samsquanch