删除或实体框架迁移重新创建数据库(code-一)实体、框架、数据库、code

由网友(我讨厌你践踏我的尊严、)分享简介:这是命令的重新或降的数据库时,使用实体框架迁移,不可以 初始值?Which is the command to recreate or drop the database when using Entity Framework Migrations, not Initializers?我应该写在包管理器控制台?注释...

这是命令的重新或降的数据库时,使用实体框架迁移,不可以 初始值

Which is the command to recreate or drop the database when using Entity Framework Migrations, not Initializers?

我应该写在包管理器控制台

注释

我在找一些命令,让我相同的功能 Database.SetInitializer<>(新DropCreateDatabaseIfModelChanges<>()); 但与迁移的办法。

I'm looking for some command that gives me the same functionality as Database.SetInitializer<>(new DropCreateDatabaseIfModelChanges<>()); but with the migrations approach.

推荐答案

您可以通过使用自动迁移获得与迁移相同的行为。

You can get the same behavior with Migrations by using automatic migrations.

PM> enable-migrations -EnableAutomaticMigrations

在Configuration.cs在构造函数中,确保自动迁移,并允许数据丢失都设置为true ...

In Configuration.cs in the constructor, make sure automatic migrations and allow data loss are set to true...

public Configuration()
{
    AutomaticMigrationsEnabled = true;
    AutomaticMigrationDataLossAllowed = true;
}

现在,每当你的模式的转变,只是执行更新数据库...

Now whenever your model changes, just execute update-database...

PM> update-database

该模式将被改变以匹配模型和表中的任何现有数据将在那里逗留(除非它是一个重命名或删除列)。该种方法被运行后,对数据库进行更新,因此您可以进一步控制在有任何改变的数据。

The schema will be changed to match the models and any existing data in the tables will stay there (unless it's in a renamed or removed column). The Seed method is run after the database is updated so you can further control any changes to the data in there.

阅读全文

相关推荐

最新文章