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 tablecontentsadd constraintcontents_cms_id_foreignforeign k ey (cms_id) referencesinventories(remote_id))[PDOException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
cms_idandremote_idare of the same type, size and have the same properties (like e.g.UNSIGNEDetc.). - lesssugar