I'm having trouble creating foreign keys in mysql
through phpmyadmin
.
I have these tables
CREATE TABLE 'cidade' (
'idCidade' int PRIMARY KEY AUTO_INCREMENT,
'nome' varchar(25),
'Uf' CHAR(2)
);
CREATE TABLE 'aeroporto' (
'idAeroporto' int PRIMARY KEY AUTO_INCREMENT,
'nome' varchar(100),
'endereco' varchar(200),
'idCidade' integer
);
But when I try to create the relationship
ALTER TABLE 'usuario' ADD CONSTRAINT 'fk_cidadeUsuario' FOREIGN KEY ('idCidade')
REFERENCES 'cidade' ('idCidade');
I have the following error:
#1005 - Can't create table 'trab_tsnet_142'.'#sql-1a80_281' (errno: 150 "Foreign key constraint is incorrectly formed")
What could be happening?
(obs: this is just one of the relationships that is giving error, I have the same problem in other relationships).