0

I have a table named "countries" and another table named "country_continents" in my DB. I want to make my continent_id column in countries , a foreign key referencing the id of country_continents, but I am getting an error message. This is the SQL to create the foreign key and the error:

ALTER TABLE countries
    ADD CONSTRAINT fk_continent_id
    FOREIGN KEY (continent_id)
    REFERENCES country_continents(id);

ERROR: #1215 - cannot add foreign key constraint

At first, I was getting the :

"Error: relational features are disabled"

so I ran the command ALTER TABLE countries ENGINE=InnoDB; and ALTER TABLE country_continents ENGINE=InnoDB; but now I'm getting the #1215 error.

This is the Structure for "country_continents": enter image description here

This is the Structure for "countries": enter image description here

Any ideas on whats happening? Thanks in advance.

mlila_p
  • 111
  • 14

1 Answers1

1

I think the error is due to:

in your countries table, continent_id is not unsigned. Edit that and tell me if it worked

Atika
  • 1,025
  • 2
  • 6
  • 17