這裏是我的表:的MySQL(InnoDB的):需要刪除列,以及伴隨外鍵約束和索引
CREATE TABLE `alums_alumphoto` (
`id` int(11) NOT NULL auto_increment,
`alum_id` int(11) NOT NULL,
`photo_id` int(11) default NULL,
`media_id` int(11) default NULL,
`updated` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `alums_alumphoto_alum_id` (`alum_id`),
KEY `alums_alumphoto_photo_id` (`photo_id`),
KEY `alums_alumphoto_media_id` (`media_id`),
CONSTRAINT `alums_alumphoto_ibfk_1` FOREIGN KEY (`media_id`) REFERENCES `media_mediaitem` (`id`),
CONSTRAINT `alum_id_refs_id_706915ea` FOREIGN KEY (`alum_id`) REFERENCES `alums_alum` (`id`),
CONSTRAINT `photo_id_refs_id_63282119` FOREIGN KEY (`photo_id`) REFERENCES `media_mediaitem` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8
我想刪除列photo_id
,這大概還需要刪除外鍵約束,該指數。
的問題是,我得到的錯誤,當我嘗試刪除列:
ERROR 1025 (HY000): Error on rename of '.\dbname\#sql-670_c5c' to '.\dbname\alums_alumphoto' (errno: 150)
...當我嘗試刪除索引(同上),當我嘗試刪除外關鍵約束:
ERROR 1091 (42000): Can't DROP 'photo_id_refs_id_63282119'; check that column/key exists)
什麼順序我應該做的所有這一切?我應該使用哪些精確的命令?
您是否嘗試過在同一個ALTER語句中刪除列和索引? – staticsan 2008-12-03 23:30:24