Does anyone know why I can’t create FK?

Asked

Viewed 20 times

0

I cannot create the fk’s from the location table, appears Error Code: 1215. Cannot add Foreign key Constraint

create table automovel(
placa varchar(7) not null,
cor varchar(20),
num_portas int,
tp_combus varchar(30),
km float not null,
renavam float not null,
chassi varchar(30) not null,
vlr_loca float,
modelo varchar(30) not null,
marca varchar(20),

primary key (placa)
);

create table locacao(
pedido int auto_increment not null,
placa varchar(7),
dt_loca date,
hr_loca datetime,
dt_dev date,
hr_dev datetime,
km float,
vlr_loca float,
dev int,

primary key (pedido),
FOREIGN KEY (placa) REFERENCES automovel(placa),
FOREIGN KEY (km) REFERENCES automovel(km),
FOREIGN KEY (vlr_loca) REFERENCES automovel(vlr_loca)


);
  • 1

    The foreing key ONLY connects to the Primary Key of the referenced table.

  • Our really, I didn’t pay attention. Thank you friend!

  • @Motta put his comment as answer so he can choose as the best answer and close the question.

1 answer

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.