我们如何删除实体框架核心代码中的第一次迁移第一种方法
正如我们知道何时要删除最新迁移时,我们将数据库更新为最新迁移能够删除第一次迁移,有人可以为此提供帮助。
As we know when we want to remove latest migration, We update the database to latest but one migration so we can remove the latest migration but if want to remove first migration don't have latest but one migration to update database into it, So not able to remove first migration, Can someone help with this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了将数据库重置为干净的状态,在第一次迁移使用之前,
该数据库将回滚第一个迁移。假设您从一个新的数据库开始,此时数据库中唯一的事情是
__ efmigrationshistory
表。那时,您可以使用
删除移民
来删除第一个迁移。您还可以使用
Update-Database 0
来创建初始数据库,而无需任何迁移。To reset the database to a clean state, prior to the first migration use
This will rollback the first migration. Assuming you started with a new database, the only thing in the database at this point would be the
__EFMigrationsHistory
table.At that point, you can use
Remove-Migration
to remove the very first migration.You can also use
Update-Database 0
to create the initial database without any migrations.数据库中有一个表 efmigrationshistory 。如果您删除其中的任何人,并且当您迁移时,Eframework将检查该表。它将看到第一个迁移不存在,并且会更新您的数据库(对齐无关紧要,我的意思是,它可能是第三或第8迁移)。
而且有一个名为BaseContextModelsNapshot的类,有时您需要在必要时进行编辑。
There is a table EfMigrationsHistory in your database . If you delete anyone of them and when you migrate , eframework will check that table .And it will see that the first migration does not exist and will update your database (alignment does not matter , I mean it could be 3rd or 8th migration).
And there is one class named BaseContextModelSnapshot , occasionally you need to edit if necessary .