Support the ongoing development of Laravel.io →
Database Eloquent Installation
Last updated 2 years ago.
0

Generally that means a type error between the two columns. I think there is a problem is the "models" table as the user_id on it might not be unsigned because there's a spelling error on the "->unsigned()" which would prevent it from being an unsigned int like on the "model_photosets" table. Check your database to confirm if you have the right data type on the models table.

0

rowright said:

Thanks for the answer. I tried to correct the spelling error in the type name (table models) and completely remove it, but it did not help me :c

Last updated 7 years ago.
0

@MyZik:

Follow below steps:

  1. Run migration first for 'photoset_categories' and 'models'
  2. Run migration for 'model_photosets' once above step 1) migration done

Here, the problem is your 'model_photosets' table migration run before the foreign key table migration(i.e. 'photoset_categories' and 'models')

Hope this works for you!

0

saurabhd said:

Hi! Thanks for the answer. I did everything as you said, but the error remained. I noticed a feature: when I change foreign key user_id to id it works. But this is not what I need.

0

Use below code in your CreateModelPhotosetsTable migration file

class CreateModelPhotosetsTable extends Migration
{
   /**
    * Run the migrations.
    *
    * @return void
    */
   public function up()
   {
       Schema::create('model_photosets', function (Blueprint $table) {
           $table->increments('id');
           $table->integer('model_id')->unsigned();
           $table->foreign('model_id')->references('user_id')->on('models')->onDelete('cascade')->unique()->unsigned();

           $table->integer('category_id')->unsigned();
           $table->foreign('category_id')->references('id')->on('photoset_categories')->onDelete('cascade');
       });
   }
}

Hope this work for you !

0

Sign in to participate in this thread!

Eventy

Your banner here too?

MyZik myzik Joined 16 Apr 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.