#1025 - 重命名“./database/#sql-2e0f_1254ba7”时出错到“./database/table” (错误号:150)
因此,我尝试向数据库中的一个表添加主键。现在它有一个像这样的主键:
PRIMARY KEY (user_id, round_number)
其中 user_id 是外键。
我试图将其更改为:
PRIMARY KEY (user_id, round_number, created_at)
我通过单击表结构视图中的主键图标在 phpmyadmin 中执行此操作。
这是我得到的错误:
#1025 - Error on rename of './database/#sql-2e0f_1254ba7' to './database/table' (errno: 150)
它是一个带有 InnoDB 表引擎的 MySQL 数据库。
So I am trying to add a primary key to one of the tables in my database. Right now it has a primary key like this:
PRIMARY KEY (user_id, round_number)
Where user_id is a foreign key.
I am trying to change it to this:
PRIMARY KEY (user_id, round_number, created_at)
I am doing this in phpmyadmin by clicking on the primary key icon in the table structure view.
This is the error I get:
#1025 - Error on rename of './database/#sql-2e0f_1254ba7' to './database/table' (errno: 150)
It is a MySQL database with InnoDB table engine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
可能还有另一个表的外键引用您尝试更改的主键。
要找出导致错误的表,您可以运行 SHOW ENGINE INNODB STATUS ,然后查看 LATEST FOREIGN KEY ERROR 部分。
There is probably another table with a foreign key referencing the primary key you are trying to change.
To find out which table caused the error you can run
SHOW ENGINE INNODB STATUS
and then look at theLATEST FOREIGN KEY ERROR
section.正如之前所说,您需要删除 FK。在Mysql上这样做:
As was said you need to remove the FKs before. On Mysql do it like this:
对于那些通过谷歌解决这个问题的人...如果您尝试重命名充当外键的字段,也可能会发生此错误。
For those who are getting to this question via google... this error can also happen if you try to rename a field that is acting as a foreign key.
要在 PHPMyAdmin 或 MySQL 中绕过此问题,请先删除外键约束,然后再重命名属性。
(对于 PHPMyAdmin 用户:要删除 PHPMyAdmin 中的 FK 约束,请选择该属性,然后单击表结构下方工具栏中“打印视图”旁边的“关系视图”)
To bypass this in PHPMyAdmin or with MySQL, first remove the foreign key constraint before renaming the attribute.
(For PHPMyAdmin users: To remove FK constrains in PHPMyAdmin, select the attribute then click "relation view" next to "print view" in the toolbar below the table structure)
如果您尝试删除外键列,则必须找到不是列名的正确名称。例如:如果我尝试删除警报表中的服务器字段,该字段是服务器表的外键。
显示创建表警报;
查找
CONSTRAINT `server_id_refs_id_34554433` FORIEGN KEY (`server_id`) REFERENCES `server` (`id`)
行。ALTER TABLE `alarm` DROP FOREIGN KEY `server_id_refs_id_34554433`;
ALTER TABLE `alarm` DROP `server_id`
这将从 Alarms 表中删除外键服务器。
If you are trying to delete a column which is a FOREIGN KEY, you must find the correct name which is not the column name. Eg: If I am trying to delete the server field in the Alarms table which is a foreign key to the servers table.
SHOW CREATE TABLE alarm;
Look for the
CONSTRAINT `server_id_refs_id_34554433` FORIEGN KEY (`server_id`) REFERENCES `server` (`id`)
line.ALTER TABLE `alarm` DROP FOREIGN KEY `server_id_refs_id_34554433`;
ALTER TABLE `alarm` DROP `server_id`
This will delete the foreign key server from the Alarms table.
我遇到了这个问题,它是针对外键的
单击
关系视图
(如下图所示),然后找到要删除它的字段的名称,然后在外键约束(INNODB)
列下,只需将选择设置为空即可!表示没有外键希望有效!
I had this problem, it is for foreign-key
Click on the
Relation View
(like the image below) then find name of the field you are going to remove it, and under theForeign key constraint (INNODB)
column, just put the select to nothing! Means no foreign-keyHope that works!
如果您在添加外键时遇到此错误,则可能是子表中的值不存在于父表中。
假设必须添加外键的列的所有值都设置为 0,并且该值在您引用它的表中不可用。
您可以设置父表中存在的一些值,然后添加外键对我有用。
If you are adding a foreign key and faced this error, it could be the value in the child table is not present in the parent table.
Let's say for the column to which the foreign key has to be added has all values set to 0 and the value is not available in the table you are referencing it.
You can set some value which is present in the parent table and then adding foreign key worked for me.