efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Generated migration cannot update SQLite database.

Open delautour opened this issue 10 years ago • 6 comments

When making a code first change which adds a relationship between models, dnx ef migrations add xyz creates a migration file which causes dnx ef database update to fail with System.NotSupportedException: SQLite cannot support this migration operation.

A comment in SqliteMigrationsSqlGenerator would appear to indicate the issue in in migration generation.

For example, see the second commit of https://github.com/Amerdrix/SQLite-Migration. Note that all migrations have been committed as generated by tooling.

delautour avatar Dec 13 '15 03:12 delautour

This requires #329. SQLite doesn't support dropping columns, altering columns, adding constraints, dropping constraints, etc.

bricelam avatar Dec 14 '15 17:12 bricelam

SQL Compact does, though...

ErikEJ avatar Dec 14 '15 17:12 ErikEJ

Triage: This is just a limitation of using SQLite, we have https://github.com/aspnet/EntityFramework.Docs/issues/32 tracking documenting these limitations.

rowanmiller avatar Jan 06 '16 23:01 rowanmiller

I fixed this with dropping the whole database, then deleting the whole migrations folder and then just building database with adding new "InitialCreated" database. The worst part will be if you already had some input data (not from template seed file). Then you will lose this all, which in my case wasn't there.

faridhuseynov avatar Oct 10 '19 21:10 faridhuseynov

I fixed this with dropping the whole database, then deleting the whole migrations folder and then just building database with adding new "InitialCreated" database. The worst part will be if you already had some input data (not from template seed file). Then you will lose this all, which in my case wasn't there.

But it seems to be a problem if we are going to create big structure and start loosing our data in each set

DevbMindfire avatar Apr 23 '20 23:04 DevbMindfire

Thanks @faridhuseynov It worked for me too, this is a limitaion tracked in the docs. But have some work arrounds.

You can workaround some of these limitations by manually writing code in your migrations to perform a rebuild. Table rebuilds involve creating a new table, copying data to the new table, dropping the old table, renaming the new table. You will need to use the Sql(string) method to perform some of these steps.

Galaxs avatar Oct 12 '20 00:10 Galaxs