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

所以我试图向我的数据库中的一个表添加主键.现在它有一个这样的主键:

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)

其中 user_id 是外键.

Where user_id is a foreign key.

我正在尝试将其更改为:

I am trying to change it to this:

PRIMARY KEY (user_id, round_number, created_at)

我在 phpmyadmin 中通过单击表结构视图中的主键图标来执行此操作.

I am doing this in phpmyadmin by clicking on the primary key icon in the table structure view.

这是我得到的错误:

#1025 - Error on rename of './database/#sql-2e0f_1254ba7' to './database/table' (errno: 150)

它是一个带有 InnoDB 表引擎的 MySQL 数据库.

It is a MySQL database with InnoDB table engine.

推荐答案

可能有另一个表的外键引用了您要更改的主键.

There is probably another table with a foreign key referencing the primary key you are trying to change.

要找出导致错误的表,您可以运行 SHOW ENGINE INNODB STATUS 然后查看 LATEST FOREIGN KEY ERROR 部分.

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.

相关文章