vendredi 20 mai 2016

Laravel Migration issue : Table self relation

I have the following migration :

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');
        });

The following issue comes up:

 (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)

Everything is good. I have checked alot but not working.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1TjqNFQ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire