Mysql外键创建1005 - Can't create table 'ds_article.#sql-770_b2' (errno: 150)错误
我要建两个表第一个DROPTABLEIFEXISTS`ds_admin`;CREATETABLE`ds_admin`(`Admin_ID`int(11)NOTNULLAU...
我要建两个表第一个
DROP TABLE IF EXISTS `ds_admin`;
CREATE TABLE `ds_admin` (
`Admin_ID` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(20) NOT NULL,
`password` varchar(26) NOT NULL,
PRIMARY KEY (`Admin_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
第二个
DROP TABLE IF EXISTS `admin_log`;
CREATE TABLE `admin_log` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Admin_ID` int(11) DEFAULT NULL,
`time` date DEFAULT NULL,
`viscera` varchar(1000) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
我想创建admin_log表和ds_admin表的Admin_ID相连但是报1005 - Can't create table 'ds_article.#sql-770_b2' (errno: 150)错误,我的表类型都是InnoDB而且数据类型长度都一样问什么不能创建呢? 展开
DROP TABLE IF EXISTS `ds_admin`;
CREATE TABLE `ds_admin` (
`Admin_ID` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(20) NOT NULL,
`password` varchar(26) NOT NULL,
PRIMARY KEY (`Admin_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
第二个
DROP TABLE IF EXISTS `admin_log`;
CREATE TABLE `admin_log` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Admin_ID` int(11) DEFAULT NULL,
`time` date DEFAULT NULL,
`viscera` varchar(1000) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
我想创建admin_log表和ds_admin表的Admin_ID相连但是报1005 - Can't create table 'ds_article.#sql-770_b2' (errno: 150)错误,我的表类型都是InnoDB而且数据类型长度都一样问什么不能创建呢? 展开
3个回答
展开全部
我执行了,没问题啊,能建外键的。
mysql> DROP TABLE IF EXISTS `ds_admin`;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> CREATE TABLE `ds_admin` (
-> `Admin_ID` int(11) NOT NULL AUTO_INCREMENT,
-> `username` varchar(20) NOT NULL,
-> `password` varchar(26) NOT NULL,
-> PRIMARY KEY (`Admin_ID`)
-> ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.08 sec)
mysql>
mysql> DROP TABLE IF EXISTS `admin_log`;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> CREATE TABLE `admin_log` (
-> `ID` int(11) NOT NULL AUTO_INCREMENT,
-> `Admin_ID` int(11) DEFAULT NULL,
-> `time` date DEFAULT NULL,
-> `viscera` varchar(1000) DEFAULT NULL,
-> PRIMARY KEY (`ID`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.08 sec)
mysql>
mysql> ALTER TABLE admin_log ADD FOREIGN KEY(Admin_ID) REFERENCES ds_admin(Admin
_ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
Query OK, 0 rows affected (0.14 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> DROP TABLE IF EXISTS `ds_admin`;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> CREATE TABLE `ds_admin` (
-> `Admin_ID` int(11) NOT NULL AUTO_INCREMENT,
-> `username` varchar(20) NOT NULL,
-> `password` varchar(26) NOT NULL,
-> PRIMARY KEY (`Admin_ID`)
-> ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.08 sec)
mysql>
mysql> DROP TABLE IF EXISTS `admin_log`;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> CREATE TABLE `admin_log` (
-> `ID` int(11) NOT NULL AUTO_INCREMENT,
-> `Admin_ID` int(11) DEFAULT NULL,
-> `time` date DEFAULT NULL,
-> `viscera` varchar(1000) DEFAULT NULL,
-> PRIMARY KEY (`ID`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.08 sec)
mysql>
mysql> ALTER TABLE admin_log ADD FOREIGN KEY(Admin_ID) REFERENCES ds_admin(Admin
_ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
Query OK, 0 rows affected (0.14 sec)
Records: 0 Duplicates: 0 Warnings: 0
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-09-24
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-09-23
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |