0
我想在具有外鍵的數據庫中創建表。我錯過了什麼?mysql創建外鍵失敗的表
CREATE TABLE `users` (
`id` bigint(10) NOT NULL AUTO_INCREMENT,
`userName` varchar(24) NOT NULL DEFAULT '',
`password` varchar(32) NOT NULL DEFAULT '',
`firstName` varchar(32) NOT NULL DEFAULT '',
`lastName` varchar(32) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1
CREATE TABLE `topLevelPermissions` (
`id` bigint(10) NOT NULL AUTO_INCREMENT,
`userId` bigint(10) NOT NULL DEFAULT '0',
`user` char(1) NOT NULL DEFAULT '0',
`group` char(1) NOT NULL DEFAULT '0',
`someField` char(1) NOT NULL DEFAULT '0',
`someOtherField` char(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
FOREIGN KEY (`userId`) REFERENCES users (`id`) ON DELETE CASCADE
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1
我看不出任何與外鍵相關的東西。事實上,當我
show create table topLevelPermissions;
我看到
CREATE TABLE `topLevelPermissions` (
`id` bigint(10) NOT NULL AUTO_INCREMENT,
`userId` bigint(10) NOT NULL DEFAULT '0',
`user` char(1) NOT NULL DEFAULT '0',
`group` char(1) NOT NULL DEFAULT '0',
`someField` char(1) NOT NULL DEFAULT '0',
`someOtherField` char(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `userId` (`userId`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1
Innodb只支持外鍵約束 –
使它成爲答案,我會在11分鐘內接受。 – bart2puck
謝謝@ bart2puck –