我想将 an 修改index(col1, col2, col3)
为 anindex(col1)
而不会激怒col1
. 我该怎么做?
我的方法是删除并创建索引。但是它在执行时使外键失败。升级和还原架构的步骤是什么?
原来的:
`sid` int(11) NOT NULL DEFAULT '0',
`cid` int(11) NOT NULL DEFAULT '0',
`uid` int(11) NOT NULL DEFAULT '0',
...
UNIQUE KEY `User_sid` (`sid`,`cid`,`uid`),
...
CONSTRAINT `User_ibfk_1` FOREIGN KEY (`sid`) REFERENCES `SolrMap` (`sid`)
客观的:
...,
`sid` int(11) NOT NULL DEFAULT '0',
`cid` int(11) NOT NULL DEFAULT '0', ####ONE LESS COLUMN
`password_reset_valid_until` datetime DEFAULT NULL,
`password_reset_id` char(24) DEFAULT NULL,
...
KEY `User_sid` (`sid`) ####NEW KEY
####WANT NEW FOREIGN KEY
这就是我尝试但失败的方法:
ALTER TABLE `User`
DROP INDEX `User_sid`,
ADD INDEX `User_sid` (`sid`) USING BTREE,
DROP COLUMN `uid`;
这就是它失败的原因:
------------------------
LATEST FOREIGN KEY ERROR
------------------------
121013 8:27:39 Error in foreign key constraint of table friday/User:
there is no index in the table which would contain
the columns as the first columns, or the data types in the
table do not match the ones in the referenced table
or one of the ON ... SET NULL columns is declared NOT NULL. Constraint:
,
CONSTRAINT "User_ibfk_1" FOREIGN KEY ("sid") REFERENCES "SolrMap" ("sid")
InnoDB: Renaming table `friday`.<result 2 when explaining filename '#sql-6fd_2f12e'> to `friday`.`User` failed!