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.
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
Follow below steps:
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!
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.
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 !
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community