0
有人想法,爲什麼這個SQL返回錯誤創建表帳戶?InnoDB錯誤與創建表
1005 - 無法創建表「mobilewaiter.accounts」(錯誤:150)
我看到,這個問題可以與鍵索引,但一切都在主鍵參考。 幫幫我,謝謝。
CREATE TABLE IF NOT EXISTS `tables` (
`_id` int(10) NOT NULL AUTO_INCREMENT,
`tag` varchar(40) COLLATE utf8_czech_ci NOT NULL,
`name` varchar(40) COLLATE utf8_czech_ci NOT NULL,
`occupied` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `users` (
`_id` int(10) NOT NULL AUTO_INCREMENT,
`nick` varchar(20) COLLATE utf8_czech_ci NOT NULL,
`password` varchar(40) COLLATE utf8_czech_ci NOT NULL,
`salt` varchar(20) COLLATE utf8_czech_ci NOT NULL,
`email` varchar(50) COLLATE utf8_czech_ci NOT NULL,
`firstname` varchar(20) COLLATE utf8_czech_ci NOT NULL,
`lastname` varchar(20) COLLATE utf8_czech_ci NOT NULL,
`role` varchar(20) COLLATE utf8_czech_ci NOT NULL,
PRIMARY KEY (`_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `accounts` (
`_id` int(10) NOT NULL AUTO_INCREMENT,
`table_id` varchar(10) COLLATE utf8_czech_ci NOT NULL,
`state` varchar(20) COLLATE utf8_czech_ci NOT NULL DEFAULT 'created',
`user_id` int(10) NOT NULL,
`start_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`end_time` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`_id`),
FOREIGN KEY (`table_id`) REFERENCES `tables`(`_id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`user_id`) REFERENCES `users`(`_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;
在省略外鍵時它是否正在工作? – Hajo 2012-04-19 23:03:21
是的,問題在那裏。但我需要它,所以我需要知道,究竟是什麼導致了這個錯誤。我還創建了另一個表,該表與表用戶建立連接,並且該表將創建而不會出錯。 – Vaek 2012-04-20 10:16:44
您是否嘗試過其他外鍵名稱?也許他們會碰到索引等。 – Hajo 2012-04-20 10:53:23