Hi, could you help me? I am trying to add the FK in the table officials, only it is giving this error OBS I am creating the other tables before the officials
20:29:15 CREATE TABLE Funcionarios( id INT(5) NOT NULL AUTO_INCREMENT, nomeCompleto VARCHAR(120) NOT NULL, cpf VARCHAR(11) NOT NULL, rg VARCHAR(15) NOT NULL, pis VARCHAR(20) NOT NULL, numeroDaCarteira VARCHAR(25) NOT NULL, dataNascimento DATE NOT NULL, dataEntrada DATE NOT NULL, dataSaida DATE NULL, endereco VARCHAR(80), bairro VARCHAR(50), cidade VARCHAR(50), estado CHAR(2), telefone VARCHAR(15), salario VARCHAR(10), agencia VARCHAR(10), conta VARCHAR(10), idCargo INT(5), idSetor INT(5), codBanco INT(5), idEstadocivil INT(5), PRIMARY KEY (id), FOREIGN KEY (idCargo) REFERENCES Cargo(id), FOREIGN KEY (idSetor) REFERENCES Setor (id), FOREIGN KEY (codBanco) REFERENCES Banco (codigo), FOREIGN KEY (idEstadocivil) REFERENCES EstadoCivil (id) ) Error Code: 1215. Cannot add foreign key constraint 0.735 sec
I do not know what to do, I'm having to pack and nothing, could you help me?
CREATE DATABASE Empresa2;
CREATE TABLE Funcionarios(
id INT(5) NOT NULL AUTO_INCREMENT,
nomeCompleto VARCHAR(120) NOT NULL,
cpf VARCHAR(11) NOT NULL,
rg VARCHAR(15) NOT NULL,
pis VARCHAR(20) NOT NULL,
numeroDaCarteira VARCHAR(25) NOT NULL,
dataNascimento DATE NOT NULL,
dataEntrada DATE NOT NULL,
dataSaida DATE NULL,
endereco VARCHAR(80),
bairro VARCHAR(50),
cidade VARCHAR(50),
estado CHAR(2),
telefone VARCHAR(15),
salario VARCHAR(10),
agencia VARCHAR(10),
conta VARCHAR(10),
idCargo INT(5),
idSetor INT(5),
codBanco INT(5),
idEstadocivil INT(5),
PRIMARY KEY (id),
FOREIGN KEY (idCargo) REFERENCES Cargo(id),
FOREIGN KEY (idSetor) REFERENCES Setor (id),
FOREIGN KEY (codBanco) REFERENCES Banco (codigo),
FOREIGN KEY (idEstadocivil) REFERENCES EstadoCivil (id)
);
CREATE TABLE EstadoCivil(
id INT(5) NOT NULL AUTO_INCREMENT,
referencia VARCHAR(50),
PRIMARY KEY (id)
);
CREATE TABLE Cargo(
id INT(5) NOT NULL AUTO_INCREMENT,
referencia VARCHAR(50),
PRIMARY KEY (id)
);
CREATE TABLE Setor(
id INT(5) NOT NULL AUTO_INCREMENT,
referencia VARCHAR(50),
PRIMARY KEY (id)
);
CREATE TABLE Banco(
id INT(5) NOT NULL AUTO_INCREMENT,
referencia VARCHAR(50),
codigo int(5),
PRIMARY KEY (id)
);