AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

SQLite :Replace Many schema change operations are not supported by the EF Core SQLite provider.

Open Rick-Anderson opened this issue 7 years ago • 11 comments

Replace Many schema change operations are not supported by the EF Core SQLite provider. with include

[!INCLUDE[](~/includes/RP-mvc-shared/sqlite-warn.md)]

See also #11335


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Rick-Anderson avatar Dec 13 '18 01:12 Rick-Anderson

Actually the only workaround to continue with the tutorial was to add the new fields to the initial migration and drop the database. Comments would be needed to properly work on this.

nitzer avatar Feb 24 '19 02:02 nitzer

Actually the only workaround to continue with the tutorial was to add the new fields to the initial migration and drop the database.

I was able to continue by deleting the Database file and the entire Migrations folder, and then recreating the initial migration:

> dotnet ef migrations add InitialCreate
> dotnet ef database update

...which accomplished the same thing.

El-Servas avatar May 09 '19 13:05 El-Servas

As a way to explorer the options under dotnet ef migrations, instead of deleting the migrations folder, I ran

dotnet ef migrations remove

and then continue with the steps used to add/create the database under Add Model

dotnet ef migrations add InitialCreate
dotnet ef database update

celsoglima avatar May 22 '19 15:05 celsoglima

@celsoglima thanks for your comment

dotnet ef migrations remove

is the right approach. @tdykstra is this the approach we want to use on the next update?

Rick-Anderson avatar May 22 '19 18:05 Rick-Anderson

is this the approach we want to use on the next update?

Yes, it looks better than deleting the Migrations folder.

tdykstra avatar May 22 '19 23:05 tdykstra

Don't forget that you cannot remove migrations if you have database in production. You always have to migrate from the old schema to the new schema. If something is not supported out of the box (in Entity Framework or database) you have to write migration manually in raw SQL - there is no other choice.

Andrzej-W avatar Jun 26 '19 15:06 Andrzej-W

To get around the SQLite limitations, first save all project files containing the new Model. Then:

  1. Delete MvcMovie.db
  2. Delete all files under the Migrations subfolder.
  3. Run "dotnet ef migrations add Initial"
  4. Run "dotnet ef database update"
  5. Run the project.

juliuso avatar Jul 21 '19 21:07 juliuso

@juliuso a better approach Replace 1 with dotnet ef database drop

Rick-Anderson avatar Jul 22 '19 03:07 Rick-Anderson

I did try running 'dotnet ef migrations remove' twice since there were two existing migrations, but those attempts failed. Perhaps it's better to use postgres or MySQL in future tutorials to sidestep this entirely.

juliuso avatar Jul 22 '19 18:07 juliuso

@tdykstra maybe we need a backup approach that includes manual delete of db.

Rick-Anderson avatar Jul 22 '19 18:07 Rick-Anderson

@Rick-Anderson @juliuso I'm addressing a similar situation while adding SQLite to the 3.0 version of the EF RP series. Essentially recommending the @juliuso sequence with the suggested change to step 1, for dealing with data model changes in the tutorial that SQLite can't handle. Some it can handle, like new columns. In a real app you'd be writing table rebuild SQL for migrations that aren't automated. SQLite is a popular cross-platform RDBMS and I don't think the migrations issues are serious enough to abandon it for cross-platform tutorials. Showing how to do manual table rebuilds is out of scope of these tutorials now, but it may be worth adding in the future.

tdykstra avatar Jul 22 '19 22:07 tdykstra