You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using EF Core with PostgreSQL using Npgsql and I have set the Foreign Key of the dependent entity (Chapter, see below) as nullable int. I was expecting when I delete the principle entity (in this case Book) CASCADE NULL will happen. Instead in the migration the behavior is ON DELETE RESTRICT. So when I try to delete the Book entity it throws
update or delete on table "Books" violates foreign key constraint "FK_Chapters_Books_BookId" on table "Chapters"
Shouldn't it be ON DELETE SET NULL by default? How to make it SET NULL?
File a bug
I am using EF Core with PostgreSQL using Npgsql and I have set the Foreign Key of the dependent entity (Chapter, see below) as nullable int. I was expecting when I delete the principle entity (in this case Book) CASCADE NULL will happen. Instead in the migration the behavior is ON DELETE RESTRICT. So when I try to delete the Book entity it throws
Shouldn't it be ON DELETE SET NULL by default? How to make it SET NULL?
Include your code
Book entity:
Chapter entity:
Generated Migration for Chapter Entity:
As you can see above the
onDelete: ReferentialAction.Restrict)
has restrict in it. Why notSetNull
by default?Include stack traces
Include provider and version information
EF Core version: 5.0.4
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL
Target framework: .NET 5.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.10)
The text was updated successfully, but these errors were encountered: