Efcore: Generated migration cannot update SQLite database.

Created on 13 Dec 2015  路  6Comments  路  Source: dotnet/efcore

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.

Most helpful comment

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.

All 6 comments

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

SQL Compact does, though...

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

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.

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

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.

Was this page helpful?
0 / 5 - 0 ratings