Error: 150 "Foreign key constraint is incorrectly formed"
Publicado por Daniel (1 intervención) el 23/09/2018 15:07:05
Tengo el siguiente código:
Y me da el siguiente error: Error: 150 "Foreign key constraint is incorrectly formed")
Estoy ejecutando el servidor MySQL (MariaDB) sobre Debian9.
Gracias.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
CREATE TABLE IF NOT EXISTS pais(
id INT(16) AUTO_INCREMENT NOT NULL,
nombre VARCHAR(64) NOT NULL,
cod_pais INT(8) NOT NULL,
PRIMARY KEY (id,cod_pais)
);
CREATE TABLE IF NOT EXISTS provincia(
id INT(16) AUTO_INCREMENT NOT NULL,
nombre VARCHAR(64) NOT NULL,
cod_localidad INT(8) NOT NULL,
cod_pais INT(8) NOT NULL,
PRIMARY KEY (id,cod_localidad),
INDEX (cod_pais),
CONSTRAINT cod_pais_fk FOREIGN KEY (cod_pais) REFERENCES pais(cod_pais)
);
Y me da el siguiente error: Error: 150 "Foreign key constraint is incorrectly formed")
Estoy ejecutando el servidor MySQL (MariaDB) sobre Debian9.
Gracias.
Valora esta pregunta


0