Jokes1994
Jokes1994

Reputation: 25

The ALTER TABLE statement conflicted with the FOREIGN KEY constraint sql

I have this code that creates a foreign key to the table P that has to reference to table Ss. At the moment the column that I want to be a fk is bigint, not null and its default is to 0. Is this the impediment? And the StoredFile column id is not null and is filled with bigint data.

alter table P add constraint fk_fileId_p foreign key (fileID)
    references Ss(id)

Upvotes: 0

Views: 385

Answers (1)

Tyron78
Tyron78

Reputation: 4187

In order to add the FK, you have to make sure that storefileID 0 is present in the table StoredFile (e.g. by adding a dummy record) - otherwise the FK validation fails and the constraint can not be created.

Upvotes: 2

Related Questions