2016-11-02 40 views
0

我有一個奇怪的情況: 它的工作原理:不能重命名錶

rename table `test` to `test3` 

但這不起作用:在(錯誤的重命名

rename table `test` to `test1` 

錯誤:150 - 外鍵約束不正確 形成)

更新:

我設置:

SET FOREIGN_KEY_CHECKS=0; 

我沒有外鍵

enter image description here

CREATE TABLE `test` (`agglomeration_id` int(11) NOT NULL, `carpark_id` int(11) NOT NULL, `numer_urzadzenia` char(3) NOT NULL, 
         `payments_zone` char(1) DEFAULT NULL, `status` tinyint(1) DEFAULT NULL, `time_stamp` bigint(20) DEFAULT NULL, 
         `resource_uri` char(200) DEFAULT NULL, `test` int(1) NOT NULL, PRIMARY KEY (`test`)) 
    ENGINE=InnoDB DEFAULT CHARSET=utf8 
+1

是否有表外鍵約束名爲 '測試1'? –

+0

添加與此表有關的外鍵請 – rbr94

回答

0

您添加了一個外鍵測試表的列,因此這意味着你在重命名之前需要刪除約束,或者可以取消激活外鍵約束,然後重命名它。

MySQL的嘗試:

SET FOREIGN_KEY_CHECKS=0; --> Temporary disables foreign key constraints 

SQL嘗試:

EXEC sp_MSforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all" --> Disable foreign key constraints 
+0

確切的查詢在我的MySQL中工作。我寫了沒有引號的表名。 –

+0

我正在談論創建表的問題,而不是重命名它。 –

+1

SELECT DISTINCT(constraint_name) FROM information_schema.table_constraints WHERE constraint_schema ='test1' ORDER BY constraint_name ASC; –