2

application_user

-- 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;

I have a table that generated by hibernate. I want to create a table and add a foreign key manually.

So far I tried this

application_user_log

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)
) ;

And I got this error message.: [HY000][1215] Cannot add foreign key constraint

Why I got this error?

Muhammed Ozdogan
  • 5,341
  • 8
  • 32
  • 53
  • 2
    Because MyISAM does not support foreign keys –  Dec 14 '18 at 14:41
  • MyISAM doesn't support foreign keys ([details here](https://stackoverflow.com/questions/12971246/why-doesnt-mysqls-myisam-engine-support-foreign-keys)). – aBnormaLz Dec 14 '18 at 14:42
  • So what should I do to create a table that has a foreign key that referenced to a table which created by hibernate? – Muhammed Ozdogan Dec 16 '18 at 16:00

1 Answers1

0

Well I don't know why my answer got converted into a comment, but I knonw that MyISAM doesn't support foreign keys. You can read details here.

aBnormaLz
  • 809
  • 6
  • 22