admin管理员组文章数量:1202802
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?
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?
Share Improve this question edited Jan 21 at 5:39 DarkBee 15.6k8 gold badges70 silver badges114 bronze badges asked Jan 21 at 1:28 KuthKuth 155 bronze badges 2- (1) If you follow the practice of checking in all migrations to a source code repository before applying, you can look for old versions there. (2) If you work in an enterprise environment where your company has set up scheduled remote backups for your local working folders, you can look there. (3) If you have database backups, you can look there for a pre-migration copy from which you can perform a compare. (Note that in addition to schema changes, your migrations may have also added, modified, or removed data.) (4) If none of the above apply, it's time to update your devops policies. – T N Commented Jan 21 at 2:46
- So the best way is restore database backup from last date before migration new feature right? – Kuth Commented Jan 21 at 3:47
1 Answer
Reset to default 0Firstly, 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
本文标签: aspnet core mvcHow to revert to Previous Migration while Current Database is appliedStack Overflow
版权声明:本文标题:asp.net core mvc - How to revert to Previous Migration while Current Database is applied? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738658905a2105302.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论