简体   繁体   中英

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)

为了添加FK,必须确保表StoredFile中存在storefileID 0(例如,通过添加虚拟记录)-否则FK验证将失败并且无法创建约束。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM