我有一个表已创建的外键约束:Laravel改变外键约束
$table->foreign('cms_id')->references('id')->on('inventories');
我需要,使其在inventories
表引用remote_id
而不是id
列改变这种外键。
我试图通过这样做:
public function up()
{
Schema::table('contents', function (Blueprint $table) {
$table->dropForeign('contents_cms_id_foreign');
$table->foreign('cms_id')->references('remote_id')->on('inventories');
});
}
但是,我得到:
[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'和'remote_id'具有相同的类型,大小和相同的属性(如'UNSIGNED'等)。 – lesssugar
它们属于同一类型,并且具有相同的属性,但我仍然得到相同的错误 – Leff