dotnet / dotnet/efcore

Improve SQLite migrations for adding/removing NOT NULL and CHECK constraints

Open
#38,104 4 comments 1 reaction 0 assignees View on GitHub
area-migrations area-sqlite customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

### What problem are you trying to solve?

Currently, adding/removing NOT NULL and CHECK constraints performs a [table rebuild](https://learn.microsoft.com/en-us/ef/core/providers/sqlite/limitations#migrations-limitations) in SQLite. It would be more efficient to use `ALTER TABLE` statements.

### Describe the solution you'd like

The table rebuild could be simplified by issuing much simpler `ALTER TABLE` statements instead.

This is new in [SQLite 3.53.0](https://sqlite.org/releaselog/3_53_0.html) (see 3.a.)
> New SQL language features: Enhance [ALTER TABLE](https://sqlite.org/lang_altertable.html) to permit adding and removing NOT NULL and CHECK constraints.

Note that this would probably require to detect the actual SQLite version being used to know if the new `ALTER TABLE` statements can be used or if it must fallback to a table rebuild, which might be tricky.

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.