col1
에 외래 키를 분노하지 않고 index(col1, col2, col3)
을 index(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!