Jump to content

Foreign key a null


ricardoaux

Recommended Posts

Boas

Tenho as seguintes tabelas:

create table "muchatcha".FILE
(
  ID_FILE    serial UNIQUE       not NULL,
  ID_MESSAGE           serial UNIQUE                  not null,
  FILE                 bytea                          null,
  constraint PK_FILE primary key (ID_FILE)
);
create table "muchatcha"."MESSAGE"
(
  ID_MESSAGE           serial UNIQUE                  not null,
  ID_USER              serial                     not null,
  FIL_ID_MESSAGE       serial                      not null,
  CONTENT              varchar(500)                   null,
  constraint PK_MESSAGE primary key (ID_MESSAGE)
);

alter table "muchatcha".FILE
  add constraint FK_FILE_PODE_COMP_MESSAGE foreign key (ID_MESSAGE)
     references "muchatcha"."MESSAGE" (ID_MESSAGE)
     on update restrict
     on delete restrict;

alter table "muchatcha"."MESSAGE"
  add constraint FK_MESSAGE_PODE_CONTER_FILE foreign key (FIL_ID_MESSAGE)
     references "muchatcha".FILE (ID_FILE)
     on update restrict
     on delete restrict;

alter table "muchatcha"."MESSAGE"
  add constraint FK_MESSAGE_ENVIA_USER foreign key (ID_USER)
     references "muchatcha"."USER" (ID_USER)
     on update restrict
     on delete restrict;

O meu problema é que sempre que insiro uma mensagem, não posso deixar o campo FIL_ID_MESSAGE a null. O que desejava era que este campo fosse opcional.

Se me conseguires ajudar agradecia.

Cumps

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.