-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mirosoft.Data.Sqlite 7.0, SQLite Error 19: 'FOREIGN KEY constraint failed' #30081
Comments
This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate. |
@ajcvickers The code works if I use primary key to define many to many relationship, but it fails if I want to use alternate key. Thank you in advance |
@bricelam Looks like |
On further investigation, this seems to be related to the update pipeline changes in EF7. The code is dynamically creating a trigger. However, marking all tables with /cc @roji |
Notes for triage: verified that reverting to the old SQL generator fixes this. This means #29916 should cover this case. See also dotnet/EntityFramework.Docs#4241 @Eruka As a workaround, do something like this: protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.ReplaceService<IUpdateSqlGenerator, SqliteLegacyUpdateSqlGenerator>(); |
Hi, I have a many-to-many relation between entities and it worked well in EF Core 6. After update to EF Core 7 main app also works as expected but the integration tests which use inmemory Sqlite fail with exception SQLite Error 19: 'FOREIGN KEY constraint failed'.
Also in logs I can see next exception:
System.InvalidOperationException : The relationship from 'CompanyPlanSubscription.Company' to 'Company.CompanyPlanSubscriptions' with foreign key properties {'CompanyId' : int} cannot target the primary key {'Id' : Guid} because it is not compatible. Configure a principal key or a set of foreign key properties with compatible types for this relationship.
Relationships are defined in the configuration for company (EntityTypeBuilder builder):
Company creation in a tests class looks like:
Version information
Microsoft.Data.Sqlite version: 7.0.2
Target framework: .NET 7.0
Operating system: Windows 10
The text was updated successfully, but these errors were encountered: