如何从头删除和重新创建一个现有的EF代码第一个数据库 [英] How to delete and recreate from scratch an existing EF Code first database

查看:540
本文介绍了如何从头删除和重新创建一个现有的EF代码第一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS 2012中使用了EF Code First EF 5。我使用PM update-database命令,并且我有一个简单的种子方法来填充一些表中的样本数据。



我想删除并重新创建我的x.mdb。
更新历史似乎不同步。如果我在我的上下文中注释掉我所有的DBSets,update-database就没有错误地运行,但在DB中留下了一些表。由于我在DB中没有有价值的数据,所以似乎最简单的重置所有的东西。



如何完成这个?



Thx提前

解决方案

如果我理解正确...



如果您想要开始清理



1)手动删除你的Db - 无论它在哪里(我假设你有你的连接排序),或空,它更容易/更安全地删除它在一起 - 因为有 system __MigrationHistory table - 你也需要删除它。



2)删除所有迁移文件 - 位于迁移 - 并命名为数字等 - 全部删除,



3)重建您的项目包含迁移(和其他) - 并确保您的项目设置(配置)自动构建(有时可能会导致问题 - 但不太可能),



4 )再次运行添加迁移初始 - 然后更新数据库


I am using EF Code First with EF 5 in VS 2012. I use PM update-database command and I have a simple seed method to fill some tables with sample data.

I would like to delete and recreate my x.mdb. The update history seems to be out of sync. If I comment out all my DBSets in my context, update-database run with no error but leaves some tables in the DB. As I have no valuable data in the DB it seems to the simplest to reset the all thing.

How can I accomplish this?

Thx in advance

解决方案

If I'm understanding it right...

If you want to start clean:

1) Manually delete your Db - wherever it is (I'm assuming you have your connection sorted), or empty it, but easier/safer is to delete it all together - as there is system __MigrationHistory table - you need that removed too.

2) Remove all migration files - which are under Migrations - and named like numbers etc. - remove them all,

3) Rebuild your project containing migrations (and the rest) - and make sure your project is set up (configuration) to build automatically (that sometimes may cause problems - but not likely for you),

4) Run Add-Migration Initial again - then Update-Database

这篇关于如何从头删除和重新创建一个现有的EF代码第一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆