从删库到跑路

问题: delete from users_user where id=7;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (meiduo_mall.django_admin_log, CONSTRAINT django_admin_log_user_id_c564eba6_fk_users_user_id FOREIGN KEY (user_id) REFERENCES users_user (id))

删除Mysql表数据时,如果有外键关联那么
mysql> set foreign_key_checks = 0;
Query OK, 0 rows affected (0.00 sec)

mysql> delete from users_user where id=7;
Query OK, 1 row affected (0.00 sec)

mysql> set foreign_key_checks = 1;
Query OK, 0 rows affected (0.00 sec)

先取消外键关联检查,
把表数据删除,
再把外键关联检查打开.

你可能感兴趣的:(数据库)