error in foreign key creation

Asked

Viewed 25 times

0

I’m studying bank and my foreign key does not create, I know I’m doing something wrong, but I can not understand what there is.

these are the tablets I want to call'

create table tb_cardapio(
cd_cardapio int not null auto_increment,
nm_tipo varchar(100),
cd_comida int,
constraint fk_cardapio
    primary key (cd_cardapio),
constraint fk_cardapio_comida
    foreign key(cd_comida)
        references tb_cardapio(cd_comida)
);

create table tb_comida(
cd_comida int not null primary key auto_increment,
nm_comida varchar(100),
vl_comida double
);
  • 1

    you are referencing the table itself, that row references tb_cardapio(cd_comida) should be references tb_comida(cd_comida), and the create of the table "tb_food" should be first

  • ah, ok! thank you very much!

No answers

Browser other questions tagged

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