找不到任何真正帮助我的问题,所以这是另一个问题。
我正在尝试在表(部门)上设置外键约束并将其链接到表(员工)上的主键,该列在员工上称为(dno),在部门上称为(dnumber)。两个字段都是相同的类型,但我不断得到
mysql> alter table department
-> add foreign key (dnumber)
-> references employee (dno);
ERROR 1005 (HY000): Can't create table 'dba110.#sql-938_3' (errno: 150)
有什么建议么?
更新:所以我想看看我的 dno 和 dnumber 列是有符号的还是无符号的。
mysql> show create table employee;
+----------+-------------------------------------------
-------------------------------------------------------
-------------------------------------------------------
| Table | Create Table
+----------+-------------------------------------------
-------------------------------------------------------
-------------------------------------------------------
| employee | CREATE TABLE `employee` (
`Fname` varchar(8) DEFAULT NULL,
`Minit` varchar(2) DEFAULT NULL,
`Lname` varchar(8) DEFAULT NULL,
`SSN` varchar(9) NOT NULL,
`Bdate` date DEFAULT NULL,
`Address` varchar(27) DEFAULT NULL,
`Sex` varchar(1) DEFAULT NULL,
`Salary` float NOT NULL,
`Superssn` varchar(9) DEFAULT NULL,
`Dno` int(1) NOT NULL,
PRIMARY KEY (`SSN`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+----------+-------------------------------------------
-------------------------------------------------------
-------------------------------------------------------
1 row in set (0.00 sec)
mysql> show create table department;
+------------+-----------------------------------------
-------------------------------------+
| Table | Create Table
|
+------------+-----------------------------------------
-------------------------------------+
| department | CREATE TABLE `department` (
`dnumber` int(1) NOT NULL,
`dname` varchar(15) DEFAULT NULL,
`mgrssn` varchar(9) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+------------+-----------------------------------------
-------------------------------------+
1 row in set (0.00 sec)