首页 文章

ERROR 1005(HY000):'t create table ' test.sports'(错误号:150)

提问于
浏览
0

table: records

抛出错误:

ERROR 1005(HY000):无法创建表'test.sports'(错误号:150) .

我需要帮助来解决它 .

CREATE TABLE sports(
-> interest text,
-> prize_money int,
-> sp_id int NOT NULL,
-> CONSTRAINT fk_sports 
-> FOREIGN KEY(sp_id)
-> REFERENCES records(id)
-> ON DELETE CASCADE
-> ON UPDATE CASCADE
-> ) ENGINE=INNODB;

1 回答

  • 0

    您的 records 表没有名为 id 的列 . 相反,它的主键列是 student_id ,所以你可能想从 sports 中的外键引用它 . 试试这个定义:

    CREATE TABLE sports(
        interest text,
        prize_money int,
        sp_id int NOT NULL,
        CONSTRAINT fk_sports 
        FOREIGN KEY(sp_id)
        REFERENCES records(student_id)
        ON DELETE CASCADE
        ON UPDATE CASCADE
    ) ENGINE=INNODB;
    

相关问题