Answer the question
In order to leave comments, you need to log in
Can't create table, error 150?
I read about this error, however, I can not understand how to properly link the cities and countries tables. The countries table has fields id (PRIMARY KEY) and name (data type varchar(64) ). Essence of a question: how correctly to set FK that it referred to citites? And why is the error displayed?
CREATE TABLE cities (
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(64) NOT NULL,
country_id varchar(64),
UNIQUE KEY(country_id),
FOREIGN KEY(country_id) REFERENCES countries(name)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
ERROR 1005 (HY000): Can't create table 'network.cities' (errno: 150)
Answer the question
In order to leave comments, you need to log in
put away
country_id varchar(64),
UNIQUE KEY(country_id),
FOREIGN KEY(country_id) REFERENCES countries(id)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question