0

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")
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
César Rodriguez
  • 296
  • 5
  • 16
  • 2
    Post the definitions of sf_j_esp and sf_j_sisjud also. – forpas Jan 04 '21 at 17:39
  • 2
    Does this answer your question? [MySQL Creating tables with Foreign Keys giving errno: 150](https://stackoverflow.com/questions/1457305/mysql-creating-tables-with-foreign-keys-giving-errno-150) – Mark Rotteveel Jan 04 '21 at 17:48
  • Hi, guys. Thanks for your comments. The link posted by @MarkRotteveel indeed led me to an answer (I thought it wouldn't work because of the little but significant differences between MariaDB and MySQL, but I could find the precise error and correct it). It had something to do with an index I'd supressed due to some commands MySQL Workbench put in my code but MariaDB didn't recognize. – César Rodriguez Jan 07 '21 at 17:57
  • Mark's link presents an answer which teaches how to figure the error specific cause. – César Rodriguez Jan 07 '21 at 18:01

0 Answers0