I'm hitting a bug where I can't run some laravel migrations as I'm getting the error (errno: 150 "Foreign key constraint is incorrectly formed")
I have read around the subject and can't seem to work out what my problem is. The foreign key I wish to set is an unsigned integer. The data-types are the same across both tables, etc.
Here is my migration:
Schema::create('sample_migration', function (Blueprint $table) {
$table->increments('id');
$table->integer('subject_id')->unsigned();
$table->string('1');
$table->string('2');
$table->integer('3');
$table->string('4');
$table->integer('5');
$table->integer('type')->unsigned();
$table->timestamps();
$table->foreign('type')->references('subject_type')->on('some_table');
});
On some_table
I have subject_type
as an unsigned integer. Both use the same collation and encoding.
If I add a unique()
flag on the relevant fields then the migration runs smoothly, but I don't want this as there will be duplicate data.
Is there something that I am missing?