SQL Server EF Core migrations - remove historic migrations

3htmauhk  于 2022-12-22  发布在  其他
关注(0)|答案(1)|浏览(117)

I think the title is a tiny bit misleading, so let me explain what I want to do.
I have a series of EF Core migrations (about 40) and some of them are bad. This was caused by a merge when we tried to merge two different branches each with a new migration into the trunk (or master or main or whatever we're supposed to call it now) and messed up the DB snapshot real bad.
Anyway, long story short: is there a way to delete all previous migrations and pretend like we're starting from scratch, scaffolding the code-first DBContext from the current state of the DB and then create a "first" migration for new changes?
I'm assuming I'd have to delete the migrations in the data access project, plus remove the _EFMigrationsHistory table or at least truncate it.
Is there anything else I'd need to do?

mo49yndu

mo49yndu1#

If i understand correctly and we are talking about code first approach,
then you can just use "remove-migrations" command in the package manager console
and change database name in the connectionString in order to create a new
database.

相关问题