#1025 - 重命名“./database/#sql-2e0f_1254ba7”时出错到“./database/table” (错误号:150)

发布于 2024-09-30 15:36:14 字数 438 浏览 9 评论 0原文

因此,我尝试向数据库中的一个表添加主键。现在它有一个像这样的主键:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

只想待在家 2024-10-07 15:36:15

可能还有另一个表的外键引用您尝试更改的主键。

要找出导致错误的表,您可以运行 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 the LATEST FOREIGN KEY ERROR section.

﹂绝世的画 2024-10-07 15:36:15

正如之前所说,您需要删除 FK。在Mysql上这样做:

ALTER TABLE `table_name` DROP FOREIGN KEY `id_name_fk`;

ALTER TABLE `table_name` DROP INDEX `id_name_fk`;

As was said you need to remove the FKs before. On Mysql do it like this:

ALTER TABLE `table_name` DROP FOREIGN KEY `id_name_fk`;

ALTER TABLE `table_name` DROP INDEX `id_name_fk`;
顾忌 2024-10-07 15:36:15

对于那些通过谷歌解决这个问题的人...如果您尝试重命名充当外键的字段,也可能会发生此错误。

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.

等你爱我 2024-10-07 15:36:15

要在 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)

别挽留 2024-10-07 15:36:15

如果您尝试删除外键列,则必须找到不是列名的正确名称。例如:如果我尝试删除警报表中的服务器字段,该字段是服务器表的外键。

  1. 显示创建表警报;
    查找 CONSTRAINT `server_id_refs_id_34554433` FORIEGN KEY (`server_id`) REFERENCES `server` (`id`) 行。
  2. ALTER TABLE `alarm` DROP FOREIGN KEY `server_id_refs_id_34554433`;
  3. 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.

  1. SHOW CREATE TABLE alarm;
    Look for the CONSTRAINT `server_id_refs_id_34554433` FORIEGN KEY (`server_id`) REFERENCES `server` (`id`) line.
  2. ALTER TABLE `alarm` DROP FOREIGN KEY `server_id_refs_id_34554433`;
  3. ALTER TABLE `alarm` DROP `server_id`

This will delete the foreign key server from the Alarms table.

演出会有结束 2024-10-07 15:36:15

我遇到了这个问题,它是针对外键的

单击关系视图(如下图所示),然后找到要删除它的字段的名称,然后在外键约束(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 the Foreign key constraint (INNODB) column, just put the select to nothing! Means no foreign-key

enter image description here

Hope that works!

半山落雨半山空 2024-10-07 15:36:15

如果您在添加外键时遇到此错误,则可能是子表中的值不存在于父表中。

假设必须添加外键的列的所有值都设置为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文