0
你好,我有一個mysql數據庫,在它的地址表。奇怪的mysql錯誤
這是它的創建方式:
CREATE TABLE IF NOT EXISTS `addresses` (
`adr_id` int(11) NOT NULL AUTO_INCREMENT,
`per_id` int(11) NOT NULL,
`adr_street` varchar(50) NOT NULL,
`adr_houseno` int(11) DEFAULT NULL,
`adr_housenoadd` varchar(10) DEFAULT NULL,
`adr_postcode` varchar(25) NOT NULL,
`adr_city` varchar(20) NOT NULL,
`adr_type` varchar(45) DEFAULT NULL,
`cnt_id` int(11) NOT NULL,
`adr_date` date DEFAULT NULL,
`sys-mut-dt` timestamp NULL DEFAULT NULL,
`sys-mut-user` varchar(20) DEFAULT NULL,
`sys-mut-id` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`adr_id`),
KEY `per_id` (`per_id`),
KEY `cnt_id` (`cnt_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
--
ALTER TABLE `addresses`
ADD CONSTRAINT `cnt_id` FOREIGN KEY (`cnt_id`) REFERENCES `countries` (`cnt_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
ADD CONSTRAINT `per_id` FOREIGN KEY (`per_id`) REFERENCES `persons` (`per_id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
現在我想刪除約束per_id因爲我決定它是不是nessecary。所以我刪除它,看看這裏的錯誤:
SQL查詢:
ALTER TABLE `addresses` DROP INDEX `per_id`
MySQL said: Documentation
#1025 - Error on rename of './ladosa/#sql-521_d2' to './ladosa/addresses' (errno: 150)
於是我決定刪除該表並沒有約束再次創建,但是當我做了降表,我得到:
#1217 - Cannot delete or update a parent row: a foreign key constraint fails
那麼我該如何擺脫這個問題呢?