I know this question is posted a lot, and I've checked my code carefully but couldn't find the reason why when I create the table with Foreign Key, mysql gives me an error.
mysql> CREATE TABLE Act_Model(
-> code VARCHAR(8) NOT NULL,
-> model VARCHAR(64) NOT NULL,
-> PRIMARY KEY (code))ENGINE = INNODB;
Query OK, 0 rows affected (0.09 sec)
mysql> CREATE TABLE IBT_ActItem(
-> model VARCHAR(64) NOT NULL,
-> flagbit BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
-> PRIMARY KEY(model),
-> FOREIGN KEY( model) REFERENCES Act_Model(model))ENGINE = INNODB;
ERROR 1005 (HY000): Can't create table 'test.ibt_actitem' (errno: 150)
mysql> CREATE TABLE IBT_ActItem(
-> model VARCHAR(64) NOT NULL,
-> flagbit BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
-> PRIMARY KEY(model))ENGINE = INNODB;
Query OK, 0 rows affected (0.09 sec)
when I used show engins;
, for InnoDB it gave me:
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
Can you help me to find where is my mistake? Thanks