无法添加外键

时间:2014-02-14 02:29:26

标签: mysql foreign-keys innodb

任何人都可以看到下面的任何问题,继续获取ERROR 1215 (HY000): Cannot add foreign key constraint,其他表中的两个字段是确切的数据类型和大小,唯一的区别是ID列在两个表上使用auto_increment。代码正在通过命令行运行。

CREATE TABLE td_comments (
    id MEDIUMINT(7) UNSIGNED NOT NULL AUTO_INCREMENT,
    message TEXT NOT NULL,
    rid MEDIUMINT(7) UNSIGNED NOT NULL,
    status TINYINT(2) DEFAULT 1,
    ip VARCHAR(46) NOT NULL,
    added TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    `mid` MEDIUMINT(7) UNSIGNED NOT NULL,
    pur_date DATE NOT NULL,
    pur_price FLOAT(10,2) NOT NULL DEFAULT 0,
    pur_currency TINYINT(3) NOT NULL,
    PRIMARY KEY(id),
    CONSTRAINT `fk_com_mem` FOREIGN KEY(mid) REFERENCES td_members(id),
    CONSTRAINT `fk_pur_curr_curr` FOREIGN KEY(pur_currency) REFERENCES ts_currencies(id),
    INDEX(rid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE td_members (
    id MEDIUMINT(7) UNSIGNED NOT NULL AUTO_INCREMENT,
    email VARCHAR(50) NOT NULL,
    hash TEXT NOT NULL,
    firstname VARCHAR(80),
    surname VARCHAR(80),
    created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    created_ip VARCHAR(46) NOT NULL,
    status TINYINT(2) NOT NULL DEFAULT 1,
    PRIMARY KEY(id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE ts_currencies (
    id TINYINT(3) NOT NULL,
    name varchar(20) NOT NULL,
    symbol VARCHAR(10) NOT NULL,
    `default` BOOL DEFAULT 0,
    PRIMARY KEY(id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

0 个答案:

没有答案