Mysql SQLSTATE[23000]:完整性约束冲突:1452无法在laravel迁移中添加或更新子行
我正在将外键添加到我的Mysql SQLSTATE[23000]:完整性约束冲突:1452无法在laravel迁移中添加或更新子行,mysql,sql,laravel,Mysql,Sql,Laravel,我正在将外键添加到我的约会表中,我的数据库通过laravel迁移被称为arl 但当我运行迁移时: public function up() { Schema::table('appointments', function (Blueprint $table) { $table->foreign('order_detail_id')->references('id')->on('order_details'); });
约会
表中,我的数据库通过laravel迁移被称为arl
但当我运行迁移时:
public function up()
{
Schema::table('appointments', function (Blueprint $table) {
$table->foreign('order_detail_id')->references('id')->on('order_details');
});
}
我得到了这个错误:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`arl`.`#sql-5470_6`, CONSTRAINT `appointments_order_detail_id_foreign` FOREIGN KEY (`order_detail_id`) REFERENCES `order_details` (`id`)) (SQL: alter table `appointments` add constraint `appointments_order_detail_id_foreign` foreign key (`order_detail_id`) references `order_details` (`id`))
检查错误我不知道为什么sql不能识别我的表名,并将这个奇怪的名称放入arl`.`sql-5470_6
应该是arl`.`appointments
我去HeidiSQL复制反查询,我得到了相同的错误
编辑:问题在于拉拉贡本地发球,我用xampp试过,效果很好试试这个:
$table->unsignedBigInteger('order_detail_id');
$table->foreign('order_detail_id')->references('id')->on('order_details');
问题在于表名,我不知道为什么sql将我的表名设为
#sql-5470_6
请为订单详细信息和约会添加表定义。