【发布时间】:2017-11-28 09:49:06
【问题描述】:
我有现有的表 objects 与数据。现在我需要添加名为holdings 的新表,并将对象关系添加到holdings 表。在迁移文件中,我打印了这个:
$table->foreign('holding_id')->references('id')->on('holdings')->onDelete("NO ACTION");
并在尝试迁移时收到此错误
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update
a child row: a foreign key constraint fails (`kolomnaoffice`.`#sql-f10_126`
CONSTRAINT `objects_holding_id_foreign` FOREIGN KEY (`holding_id`)
REFERENCES `holdings` (`id`) ON DELETE NO ACTION) (SQL: alter table `objects` add constraint
`objects_holding_id_foreign` foreign key (`holding_id`) references `holdings`
(`id`) on delete NO ACTION)
我有正确的数据库结构(InnoDB),字段存在并且类型正确(int)。唯一不同的是表objects是填满了数据,表holdings是新的空的。
【问题讨论】:
-
尝试将其设为可为空的列
标签: mysql laravel foreign-keys migration laravel-5.4