gpt4 book ai didi

MySQL:无法删除/删除外键

转载 作者:行者123 更新时间:2023-11-29 01:34:41 25 4
gpt4 key购买 nike

这是我迄今为止尝试过的:

mysql> alter table wp_delayedCoupons_visits remove foreign key fk_targets_visits;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'foreign key fk_targets_visits' at line 1

mysql> alter table wp_delayedCoupons_visits drop foreign key fk_targets_visits;
ERROR 1091 (42000): Can't DROP 'fk_targets_visits'; check that column/key exists

还有反引号

mysql> alter table `wp_delayedCoupons_visits` remove foreign key `fk_targets_visits`;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'foreign key `fk_targets_visits`' at line 1

mysql> alter table `wp_delayedCoupons_visits` drop foreign key `fk_targets_visits`;
ERROR 1091 (42000): Can't DROP 'fk_targets_visits'; check that column/key exists

mysql> show columns in wp_delayedCoupons_visits;

+-------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+-----+---------+----------------+
| visitId | mediumint(5) | NO | PRI | NULL | auto_increment |
| visitorId | mediumint(9) | NO | | NULL | |
| urlVisited | varchar(500) | NO | | NULL | |
| fk_targets_visits | mediumint(5) | NO | UNI | NULL | |
+-------------------+--------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

有人知道什么可能导致约束不被删除或删除吗?

最佳答案

显然,您有一个名为 fk_targets_visits,但即使以 fk_ 前缀命名,也不是外键约束。

使用查找

show create table `wp_delayedCoupons_visits`

如果此表中存在外键,则通过

重新发出命令
alter table `wp_delayedCoupons_visits` drop foreign key fk_coup_visits 

假设外键名称fk_coup_visits确实存在。

关于MySQL:无法删除/删除外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57235159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com