sql外键错误?

7xzttuei  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(207)
DROP TABLE IF EXISTS userRole;
  DROP TABLE IF EXISTS account;

  CREATE TABLE account (
     lionID VARCHAR(50) NOT NULL,
     firstName VARCHAR(50) NOT NULL,
     hashedpass VARCHAR(255) NOT NULL,
     PRIMARY KEY (lionID)
   );

   CREATE TABLE roles (
     roleID INT UNSIGNED AUTO_INCREMENT NOT NULL,
     lionID VARCHAR(50) NOT NULL,
     administrator BOOLEAN NOT NULL DEFAULT False,
     qRole VARCHAR(255) NOT NULL,
     PRIMARY KEY (roleID),
     FOREIGN KEY (lionID) REFERENCES account(lionID)
   );

我很难理解为什么会出错。。roles中的外键lionid引用了account中的主键lionid,但它似乎不喜欢它。非常感谢您的帮助。

ERROR 1064 (42000) at line 76: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FOREIGN KEY lionID REFERENCES account lionID'
)' at line 8
ldxq2e6h

ldxq2e6h1#

我认为问题出在create语句中:
您需要使用语法:

CONSTRAINT `fk_account`
        FOREIGN KEY (lionID) REFERENCES account(lionID)

相关问题