dotnet / dotnet/EntityFramework.Docs

Document how to avoid issues with SQLite table rebuild in migrations

Open
#4,429 4 comments 0 reactions 0 assignees View on GitHub
area-migrations area-sqlite
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

We are using EF Core code first with an SQLite database. Recently I made a change to a model, added a migration, applied it, and everything looked good. But after some time, I noticed that our application doesn't behave as expected and I found some errors in the logs.
After some investigation it turned out that the migration rebuilt the table in the SQLite DB. And all the customizations that we added in previous migrations were lost. All triggers were dropped and a foreign key constraint I removed in a previous migration was added back.

The problematic migration contained a single `AlterColumn` statement and it was not obvious that this would have such a big impact. To remove the unwanted foreign key constraint, I had to add a new migration and write all the table rebuild code manually.

I was really surprised that the table rebuild happened magically in the background without any notice.
To make it more transparent and easier to customize, I suggest adding all the code for the table rebuild to the migration.
It would make it clear what will happen when the migration gets applied, and it would allow us to customize the migration as needed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.