Closed dandandandaann closed 2 years ago
@danielfdutra Please create a runnable project that shows this issue
@danielfdutra - It throws exception because Transaction with TransactionNumber
= C
does not exist. A nullable FK property allows you to add Movement
which does not belong to any Transaction
but FK constraint will still block you to add Movement
which references to a Transaction
which does not exist.
@bricelam - I could not find the issue for unconstrainted relationships.
I have an issue like this: https://github.com/aspnet/EntityFrameworkCore/issues/16875 Except that my Key is String which is supposed to be already nullable.
I have these classes:
The configuration is setting the key:
If I only create a new
Movement
with aTransactionNumber
and save it I get aSqliteException: SQLite Error 19: 'FOREIGN KEY constraint failed'.
. If a create bothMovement
andTransaction
together it doesn't happen.I tried changing the
TransactionNumber
toint?
and it seems to work fine this way.This issue is only happening in my test environment with Sqlite in memory creating the database codefirst. It's working fine in my production setup using MySql where the database is created independently.
Further technical details
EF Core version: Microsoft.EntityFrameworkCore 2.2.6 Database provider: Microsoft.EntityFrameworkCore.Sqlite 2.2.6 Target framework: NET Core 2.2