I have a table with an already created foreign key constraint:
$table->foreign('cms_id')->references('id')->on('inventories');
I need to change this foreign key so that it references remote_id
and not id
column in the inventories
table.
I have tried that by doing this:
public function up()
{
Schema::table('contents', function (Blueprint $table) {
$table->dropForeign('contents_cms_id_foreign');
$table->foreign('cms_id')->references('remote_id')->on('inventories');
});
}
But, I get:
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL : alter tablecontents
add constraintcontents_cms_id_foreign
foreign k ey (cms_id
) referencesinventories
(remote_id
))[PDOException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
cms_id
andremote_id
are of the same type, size and have the same properties (like e.g.UNSIGNED
etc.). – lesssugar