Error when adding foreign key to table

Asked

Viewed 196 times

0

I get the error message:

SQL Error [42703]: ERROR: column "tela_inicial_id" referenced in Foreign key Constraint does not exist ERROR: column "tela_initial_id" referenced in Foreign key Constraint does not exist ERROR: column "tela_inil_id" referenced in Foreign key Constraint does not exist

Script table start_screen:

-- criar TelaInicial 
create table tela_inicial (
    id int8 not null,
    tela_inicial_id int8 not null,
    nome_menu varchar(255),
    menu_url varchar(255),
    primary key (id)
);
create sequence tela_inicial_id_seq;

-- chave estrangeira para usuario e tela inicial
ALTER TABLE usuario ADD CONSTRAINT fk_tela_inicial_id FOREIGN KEY (tela_inicial_id) REFERENCES tela_inicial (id);
  • In your table 'user' is there this column 'tela_inicial_id'? If not, this is the problem that is being logged in.

1 answer

1

Hello, good afternoon!

You defined the id. field as the primary key and not the tela_initial_id field. vc can change in the table the primary key to be the tela_initial_id or change in the alter table command.

In the below example I changed in alter table:

-- criar TelaInicial 
create table tela_inicial (
    id int8 not null,
    tela_inicial_id int8 not null,
    nome_menu varchar(255),
    menu_url varchar(255),
    primary key (id)
);
create sequence tela_inicial_id_seq;

-- chave estrangeira para usuario e tela inicial
ALTER TABLE usuario ADD CONSTRAINT fk_id FOREIGN KEY (id) REFERENCES tela_inicial (id);

Browser other questions tagged

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