[Resolvido] FK com valores nulos
==> RESOLVIDO <==
CREATE TABLE agencia.agenda (
id bigserial NOT NULL,
id_funcionario int8 NOT NULL,
id_job int8 NULL,
id_orcamento int8 NULL,
id_prospeccao int8 NULL,
id_ticket int8 NULL,
agenda varchar( 40 ) NOT NULL,
descricao varchar( 255 ) NOT NULL,
local varchar( 80 ) NOT NULL,
horario timestamp DEFAULT current_timestamp NOT NULL,
CONSTRAINT PK_Table_7 PRIMARY KEY ( id )
) ;
ALTER TABLE agencia.agenda ADD CONSTRAINT fk_agenda_funcionarios FOREIGN KEY ( id_funcionario ) REFERENCES agencia.funcionarios( id ) ;
ALTER TABLE agencia.agenda ADD CONSTRAINT fk_agenda_jobs FOREIGN KEY ( id_job ) REFERENCES agencia.jobs( id ) ;
[...]
==> RESOLVIDO <==
Pessoal bom dia,
Estou com um problema básico nunca mexi com postgres.
Tenho uma tabela que precisa ter ligações com IDs de outras tabelas, mas não necessáriamente essas FKs tem que ser preenchidas pelo usuário, ou seja são NULL no entanto as IDs das outras tabelas são NOT NULL.
O problema é que os campos IDs são do tipo bigserial e pelo que parece o postgres não me deixa criar campos bigserial sendo NULLs
CREATE TABLE agencia.agenda (
id bigserial NOT NULL,
id_funcionario bigserial NOT NULL,
id_job bigserial NULL, -- da erro
id_orcamento bigserial NULL, -- da erro
id_prospeccao bigserial NULL, -- da erro
id_ticket bigserial NULL, -- da erro
agenda varchar( 40 ) NOT NULL,
descricao varchar( 255 ) NOT NULL,
local varchar( 80 ) NOT NULL,
horario timestamp DEFAULT current_timestamp NOT NULL,
CONSTRAINT PK_Table_7 PRIMARY KEY ( id )
) ;
Como eu faço essa ligação? alguém pode me dar uma luz?
Discussão (0)
Carregando comentários...