SQLSTATE [HY000]:常规错误:1025在Doctrine Migration中删除外键时重命名错误时出错

时间:2022-01-13 07:41:19

I am seeing the error below when I run the following query inside a Doctrine migration:

当我在Doctrine迁移中运行以下查询时,我看到以下错误:

ALTER TABLE crmpicco_course_version DROP FOREIGN KEY FK_C060B146DE13F470

ALTER TABLE crmpicco_course_version DROP FOREIGN KEY FK_C060B146DE13F470

Migration 20151209153121 failed during Execution. 
Error An exception occurred while executing 
'ALTER TABLE crmpicco_course_version DROP FOREIGN KEY FK_C060B146DE13F470':

SQLSTATE[HY000]: General error: 
1025 Error on rename of './crmpicco_dev/crmpicco_course_version' 
to './crmpicco_dev/#sql2-77c-b0a' (errno: 152)

This is the table I am trying to change:

这是我要改变的表格:

CREATE TABLE `crmpicco_course_version` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `course_id` int(11) NOT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `start_date` datetime DEFAULT NULL,
  `end_date` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `IDX_C060B146896DBBDE` (`updated_by_id`),
  KEY `IDX_C060B146DE13F470` (`course_id`),
  CONSTRAINT `FK_C060B146896DBBDE` FOREIGN KEY (`updated_by_id`) REFERENCES `crmpicco_user` (`id`),
  CONSTRAINT `FK_C060B146DE13F470` FOREIGN KEY (`course_id`) REFERENCES `crmpicco_course` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

What is preventing me from dropping this foreign key successfully?

什么阻止我成功丢弃这个外键?

When I run SHOW ENGINE INNODB STATUS I get the following:

当我运行SHOW ENGINE INNODB STATUS时,我得到以下内容:

------------------------
LATEST FOREIGN KEY ERROR
------------------------
151209 16:25:42 Error IN dropping of a FOREIGN KEY CONSTRAINT of TABLE "crmpicco_dev"."crmpicco_course_version",
IN SQL command
ALTER TABLE crmpicco_course_version DROP FOREIGN KEY FK_C060B146DE13F470
Cannot find a CONSTRAINT WITH the given id "FK_C060B146DE13F470".

1 个解决方案

#1


1  

After endless dropping and recreating of my local database I found that this was caused by Doctrine creating the same ALTER statement more than once and also in the wrong order.

在无休止地删除并重新创建我的本地数据库之后,我发现这是由Doctrine多次创建相同的ALTER语句并且顺序错误引起的。

I had to change the statements around manually to make sure I migrated data from my old table to my new table before creating the new foreign key constraint on the new table. Without this change I was getting the error above and others.

我必须手动更改语句,以确保在新表上创建新的外键约束之前将数据从旧表迁移到新表。如果没有这个改变,我会得到上面的错误和其他错误。

#1


1  

After endless dropping and recreating of my local database I found that this was caused by Doctrine creating the same ALTER statement more than once and also in the wrong order.

在无休止地删除并重新创建我的本地数据库之后,我发现这是由Doctrine多次创建相同的ALTER语句并且顺序错误引起的。

I had to change the statements around manually to make sure I migrated data from my old table to my new table before creating the new foreign key constraint on the new table. Without this change I was getting the error above and others.

我必须手动更改语句,以确保在新表上创建新的外键约束之前将数据从旧表迁移到新表。如果没有这个改变,我会得到上面的错误和其他错误。