EF Core EnsureDelete doesn't clean up _EFMigrationsHistory Table

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
Susanna
Posts: 5
Joined: Fri 03 Aug 2018 08:42

EF Core EnsureDelete doesn't clean up _EFMigrationsHistory Table

Post by Susanna » Tue 18 Dec 2018 14:51

Dear DevArt team,

I'm trying to reset the database through EnsureDelete and running the migration after.
After EnsureDelete is called all tables are deleted but the _EFMigrationsHistory table still keeps the history of the migrations and obviously doesn't run Migration again. If _EFMigrationsHistory table is manually cleaned up then migration works as expected.
Please advise.

DevArt Version 9.6.646

Thanks
Susanna

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EF Core EnsureDelete doesn't clean up _EFMigrationsHistory Table

Post by Shalex » Wed 19 Dec 2018 15:05

By Microsoft design, EnsureCreated() / EnsureDelete() do not work with __EFMigrationsHistory.

__EFMigrationsHistory is used by Code-First Migrations, so the following code will clean up the __EFMigrationsHistory table:

Code: Select all

    var migrator = context.GetService<IMigrator>();
    migrator.Migrate("0");

    // now you can call context.Database.Migrate();

Susanna
Posts: 5
Joined: Fri 03 Aug 2018 08:42

Re: EF Core EnsureDelete doesn't clean up _EFMigrationsHistory Table

Post by Susanna » Thu 20 Dec 2018 10:31

I'm getting "table or view does not exist" on the execution of migrator.Migrate("0");

Thanks for the reply

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EF Core EnsureDelete doesn't clean up _EFMigrationsHistory Table

Post by Shalex » Thu 20 Dec 2018 12:52

Susanna wrote: Thu 20 Dec 2018 10:31I'm getting "table or view does not exist" on the execution of migrator.Migrate("0");
Most likely, you removed tables with EnsureDelete(), then called migrator.Migrate("0"); that looks for the tables registered in __EFMigrationsHistory and cannot find them. If you use EnsureDelete(), clear __EFMigrationsHistory manually.

Susanna
Posts: 5
Joined: Fri 03 Aug 2018 08:42

Re: EF Core EnsureDelete doesn't clean up _EFMigrationsHistory Table

Post by Susanna » Thu 20 Dec 2018 15:17

Now I started over and not getting the exception anymore, but it seems like the code below doesn't delete the tables and I'm getting "ORA-00955: name is already used by an existing object" on next migration. Please let me know if I'm doing it wrong.
My goal is to reset the database without any manual operations.

var migrator = mContext.GetService<IMigrator>();
migrator.Migrate("0");

Thanks in advance

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EF Core EnsureDelete doesn't clean up _EFMigrationsHistory Table

Post by Shalex » Fri 21 Dec 2018 14:33

Please specify the code for reproducing the issue on an empty database, i.e. your code should create some table in the database via migration and apply migrator.Migrate("0").

Post Reply