代码之家  ›  专栏  ›  技术社区  ›  Muhammed Ozdogan

[hy000][1215]无法添加外键约束

  •  2
  • Muhammed Ozdogan  · 技术社区  · 6 年前

    应用程序用户

    -- auto-generated definition
    create table application_user
    (
      id        bigint auto_increment
        primary key,
      email     varchar(255) not null,
      is_active bit          null,
      name      varchar(255) not null,
      password  varchar(255) not null,
      surname   varchar(255) not null,
      username  varchar(255) not null
    )
      engine = MyISAM;
    

    我有一个由hibernate生成的表。 我想创建一个表并手动添加外键。

    到目前为止我试过这个

    应用程序用户日志

    CREATE TABLE application_user_log (
      log_id BIGINT NOT NULL AUTO_INCREMENT,
      fk_user_id BIGINT NOT NULL,
      old_user_name BIGINT NOT NULL,
      new_user_name BIGINT NOT NULL,
      PRIMARY KEY (log_id),
      FOREIGN KEY  (fk_user_id) REFERENCES application_user(id)
    ) ;
    

    我收到了这个错误信息。 [HY000][1215] Cannot add foreign key constraint

    为什么我会犯这个错误?

    1 回复  |  直到 6 年前
        1
  •  0
  •   aBnormaLz    6 年前

    我不知道为什么我的答案会被转换成评论,但我知道myisam不支持外键。 You can read details 在这里。