清空具有外键约束的表时报ERROR 1701(42000)
Cannot truncate a table referenced in a foreign key constraint (`laravel-test`.`bl_role_user`, CONSTRAINT `role_user_role_id_foreign` FOREIGN KEY (`role_id`) REFERENCES `laravel-test`.`bl_roles` (`id`))
解决的办法:
关闭外键约束->清空表->启动外键约束。
例子:
mysql> SET foreign_key_checks=0;
mysql> truncate table bl_roles;
mysql> SET foreign_key_checks=1;
时间: 2025-01-01 15:31:09