How to solve a error "Foreign key constraint is incorrectly formed" on CREATE TABLE

2.2k views Asked by At

Can someone spot where is the error on the following CREATE TABLE?

MariaDB 10.4.13 keeps telling me there is some problem with foreign key.

The command:

CREATE TABLE sf_rel_places_esp_sisjud (
  j_esp_id SMALLINT(5) UNSIGNED NOT NULL,
  j_sisjud_id MEDIUMINT(8) UNSIGNED NOT NULL,
  FOREIGN KEY (j_esp_id) REFERENCES sf_j_esp (id),
  FOREIGN KEY (j_sisjud_id) REFERENCES sf_j_sisjud (id))

The error response:

Error Code: 1005. Can't create table `u4599448`.`sf_rel_places_esp_sisjud`
(errno: 150 "Foreign key constraint is incorrectly formed")
0

There are 0 answers