Reputation: 15
I'm using ASP.NET Core 6 MVC, EF with Microsoft SQL Server. I have many migrations files for starting new feature of project.
The latest migration file before start is MigrationOld
.
I have these tables:
invoiceTable
customerTable
And the feature development migration files are:
migrationNewOne
migrationNewTwo
migrationNewThree
The latest migration (migrationNewThree
) adds these tables:
vendorTable
vendorAddressTable
I have applied updated database to new migrationNewThree
, but I have accidentally lost migration file of migrationNewThree
and I try to revert database by applying migrationOld
.
In the console, I get no error and it is applied with success. But it does not affect the database, all new feature tables still exist in the database.
I would like to find the solution by reverting the database to migrationOld
and clean all those table from new feature and re-apply feature table again.
How can I do that?
Upvotes: -1
Views: 37
Reputation: 28247
Firstly, if you have all the migration file which include the migrationOld . If you lose one migration file, EF Core cannot properly manage the schema for those changes because it has no reference to what was added or removed.
Since migrationNewThree is missing, EF Core cannot generate the SQL required to revert the changes. You will need to manually drop the new feature tables (vendorTable and vendorAddressTable) from your database.
DROP TABLE vendorAddressTable;
DROP TABLE vendorTable;
Then you could run the command to update the database from none to the MigrationOld
dotnet ef database update MigrationOld
Upvotes: 0