mysql 引用密钥问题,phpmyadmin 错误代码 150
mysql refference key issue, phpmyadmin error code 150
我正在尝试创建两个 table,如下所示,
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` ( `Id` int(11) NOT NULL
AUTO_INCREMENT, `UserType` varchar(32) DEFAULT NULL, `FirstName`
varchar(64) DEFAULT NULL, `LastName` varchar(64) DEFAULT NULL,
`Email` varchar(64) DEFAULT NULL, `CompanyName` varchar(64) DEFAULT
NULL, `Telephone` varchar(64) DEFAULT NULL, `Country` varchar(64)
DEFAULT NULL, `Website` varchar(64) DEFAULT NULL, `JobTitle`
varchar(64) DEFAULT NULL, `Active` int(1) DEFAULT NULL, `Notes`
text, `DateOfRegistration` datetime DEFAULT NULL, PRIMARY KEY
(`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Table structure for table `login`
--
CREATE TABLE IF NOT EXISTS `login` ( `Id` int(11) NOT NULL,
`Username` varchar(64) NOT NULL, `Email` varchar(64) NOT NULL,
`Password` varchar(64) NOT NULL, `FailedAttemptCount` int(2) NOT
NULL, `LastLogin` datetime NOT NULL, `UserLevel` int(1) NOT NULL,
`IsVerified` int(1) NOT NULL DEFAULT '0', `VerificationKey`
varchar(256) NOT NULL, `VerifiKeyCreated` datetime NOT NULL,
PRIMARY KEY (`Id`), FOREIGN KEY (`Id`) REFERENCES users.Id, UNIQUE
KEY `username` (`Username`), UNIQUE KEY `Email` (`Email`) )
ENGINE=InnoDB DEFAULT CHARSET=latin1;
我想添加一个外键,即 login.Id 引用 users.Id,但我在 phpmyadmin 中遇到错误(代码 150)。
在此先感谢您的帮助!
此致,
拉吉
应该是
REFERENCES `users`(`Id`)
而不是
REFERENCES users.Id
比照。 http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html
我正在尝试创建两个 table,如下所示,
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` ( `Id` int(11) NOT NULL
AUTO_INCREMENT, `UserType` varchar(32) DEFAULT NULL, `FirstName`
varchar(64) DEFAULT NULL, `LastName` varchar(64) DEFAULT NULL,
`Email` varchar(64) DEFAULT NULL, `CompanyName` varchar(64) DEFAULT
NULL, `Telephone` varchar(64) DEFAULT NULL, `Country` varchar(64)
DEFAULT NULL, `Website` varchar(64) DEFAULT NULL, `JobTitle`
varchar(64) DEFAULT NULL, `Active` int(1) DEFAULT NULL, `Notes`
text, `DateOfRegistration` datetime DEFAULT NULL, PRIMARY KEY
(`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Table structure for table `login`
--
CREATE TABLE IF NOT EXISTS `login` ( `Id` int(11) NOT NULL,
`Username` varchar(64) NOT NULL, `Email` varchar(64) NOT NULL,
`Password` varchar(64) NOT NULL, `FailedAttemptCount` int(2) NOT
NULL, `LastLogin` datetime NOT NULL, `UserLevel` int(1) NOT NULL,
`IsVerified` int(1) NOT NULL DEFAULT '0', `VerificationKey`
varchar(256) NOT NULL, `VerifiKeyCreated` datetime NOT NULL,
PRIMARY KEY (`Id`), FOREIGN KEY (`Id`) REFERENCES users.Id, UNIQUE
KEY `username` (`Username`), UNIQUE KEY `Email` (`Email`) )
ENGINE=InnoDB DEFAULT CHARSET=latin1;
我想添加一个外键,即 login.Id 引用 users.Id,但我在 phpmyadmin 中遇到错误(代码 150)。
在此先感谢您的帮助!
此致, 拉吉
应该是
REFERENCES `users`(`Id`)
而不是
REFERENCES users.Id
比照。 http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html