-3

此处表 SEA​​RCHAUTHOR 正在重试 CATALOGUEBASE 但代码导致以下错误:

Error Code: 1005. Can't create table 'easylibdb1.SEARCHAUTHOR' (errno: 150)

CATALOGUEBASETABLE的表结构

CREATE TABLE IF NOT EXISTS CATALOGUEBASE(

        ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
        TITLE VARCHAR(250),
        SUBTITLE VARCHAR(250),
        AUTHOR VARCHAR(100),
        EDITION VARCHAR(500) DEFAULT '',
        TITLENUMBER VARCHAR(500),
        PRIMARY KEY (ID)
    );

SEARCHAUTHOR

CREATE TABLE IF NOT EXISTS SEARCHAUTHOR(

        ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
        TITLENUMBER VARCHAR(500),
        AUTHOR VARCHAR(250) DEFAULT '',
        SEQUENCE INT UNSIGNED,
        PRIMARY KEY (ID),
        FOREIGN KEY (TITLENUMBER) REFERENCES CATALOGUEBASE (TITLENUMBER)        
    );

提前致谢。

4

1 回答 1

0

外键必须是mysql中的索引。

InnoDB 需要外键和引用键上的索引,以便外键检查可以快速且不需要表扫描。在这里阅读更多

CREATE TABLE IF NOT EXISTS CATALOGUEBASE(

    ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
    TITLE VARCHAR(250),
    SUBTITLE VARCHAR(250),
    AUTHOR VARCHAR(100),
    EDITION VARCHAR(500) DEFAULT '',
    TITLENUMBER varchar(200),
    PRIMARY KEY (ID),
    INDEX(TITLENUMBER)
);

CREATE TABLE IF NOT EXISTS SEARCHAUTHOR(

    ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
    TITLENUMBER varchar(200),
    AUTHOR VARCHAR(250) DEFAULT '',
    SEQUENCE INT UNSIGNED,
    PRIMARY KEY (ID),
    FOREIGN KEY (TITLENUMBER) REFERENCES CATALOGUEBASE(TITLENUMBER)        
);

此查询正在运行。演示

于 2013-06-13T06:24:36.593 回答