'SET foreign_key_checks = 1'不再起作用 [英] 'SET foreign_key_checks = 1' does not work again

查看:1249
本文介绍了'SET foreign_key_checks = 1'不再起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与之合作:

  • mysql:稳定的5.6.22(带瓶装)
  • MySQLWorkBench 6.2

我有以下顺序

DROP TABLE IF EXISTS invoicedetail;
DROP TABLE IF EXISTS invoiceheader;
DROP TABLE IF EXISTS product;

当我通过Java(JDBC)工作时失败,并且通过MySQLWorkBench也失败,错误消息是关于 FK Child约束(我没有确切的错误消息), Google我进行了一项研究,发现两次相同的有效解决方案.

It fails when I work through Java (JDBC) and fails through the MySQLWorkBench too, the error message is about the FK Child constraints (I don't have the exact error message), well through Google I did a research and I have found the same valid solution twice.

  • Cannot delete or update a parent row: a foreign key constraint fails
  • How to temporarily disable a foreign key constraint in MySQL?

好吧,我做了以下事情:

Well I did the following:

SET FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS invoicedetail;
DROP TABLE IF EXISTS invoiceheader;
DROP TABLE IF EXISTS product;
SET FOREIGN_KEY_CHECKS=1;

再次起作用,只是在播放,我试图再次执行

Again it works, just playing, I tried to execute again

DROP TABLE IF EXISTS invoicedetail;
DROP TABLE IF EXISTS invoiceheader;
DROP TABLE IF EXISTS product;

确保SELECT @@FOREIGN_KEY_CHECKS;返回 1

原来的错误消息不会再出现.

Well the original error message does not appears again.

同样,我在Google上进行了一项研究,发现了以下内容:

Again I did a research on Google and I found the following:

它说:It is session-based

好吧,即使:

  • mysql服务器已停止并再次重新启动
  • 工作台重新打开
  • 重新启动计算机

SELECT @@FOREIGN_KEY_CHECKS;返回 1

原始错误消息不再出现.

The original error message does not appears again.

因此似乎 'SET foreign_key_checks = 1'不能按预期工作,或者需要额外的配置/说明

Therefore seems 'SET foreign_key_checks = 1' does not work how is expected or an extra configuration/instruction is needed

我希望能够随时禁用和启用FK安全约束

I want be able to disable and enable that FK security constraint anytime

推荐答案

我在PHPMyAdmin中遇到了类似的问题.毕竟,问题在于PHPMyAdmin在默认情况下添加了"FOREIGNK_KEY_CHECKS = 1".

I had a similar problem with PHPMyAdmin. After all, the problem was that PHPMyAdmin was adding (by default) the "FOREIGNK_KEY_CHECKS=1".

当我使用PHPMyAdming查询服务器时,在页面末尾选中了启用外键检查"选项,因此查询中的"SET FOREIGN_KEY_CHECKS = 0"都没有真正起作用.

When I was querying the server with PHPMyAdming the option "Enable foreign key checks" was checked at the end of the page, so none of the "SET FOREIGN_KEY_CHECKS=0" inside my query was actually working.

请确保解决问题的方法不是这样愚蠢的事情. ;-)

Please, make sure the solution to your problem is not something so silly like this. ;-)

这篇关于'SET foreign_key_checks = 1'不再起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆