Home > Database > navicat > body text

What to do if error 1451 occurs in Navicat

爱喝马黛茶的安东尼
Release: 2019-08-06 13:55:24
Original
7922 people have browsed it

What to do if error 1451 occurs in Navicat

What should I do if error 1451 occurs in navicat?

[Err] 1451 - Cannot delete or update aparent row: a foreign key constraint fails (`test`.`orders`, 
CONSTRAINT`fk_orders_customers` FOREIGN KEY (`cust_id`) REFERENCES `customers`(`cust_id`))
Copy after login

When deleting duplicate data in navicat, the above error is reported: a foreign key prevents this operation.

Related recommendations: "Navicat for mysql graphic tutorial"

Solution:

The table has a foreign key delete There are two ways to handle the operation error:

(1) Temporarily set the foreign key to invalid

(2) Delete the data of the table related to the foreign key

1. Foreign key Failure method

mysql> SET FOREIGN_KEY_CHECKS = 0;  # 临时设置外键失效
mysql>执行操作
mysql> SET FOREIGN_KEY_CHECKS = 1;  # 操作结束后恢复外键
Copy after login

Attachment: Directly execute the sql statement through the navicat query editor

2. Method of deleting the table (this operation is generally not used)

Through the navicat tool , view the table associated with the table's foreign key, and then delete.

The above is the detailed content of What to do if error 1451 occurs in Navicat. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!