简体   繁体   English

实体代码首先迁移和删除数据库

[英]Entity code first migrations and deleting databases

We're using EF Code First and migrations for a project. 我们正在使用EF Code First和项目迁移。 We're commiting our migrations to source, and everything is great. 我们将迁移归于源头,一切都很好。 However, if someone delete's their database, or we get a new person on the project, the database will throw errors because it's trying to run the migrations. 但是,如果有人删除了他们的数据库,或者我们在项目中找到了新人,则数据库会因为尝试运行迁移而抛出错误。 Is there a way to make it so that if the database doesn't exist, it ignores migrations? 有没有办法使它如果数据库不存在,它会忽略迁移? I can't seem to find anything about this. 我似乎无法找到任何关于此的内容。

I would look at how you are using DbMigrationsConfiguration from the Entity framework. 我将看看你如何使用Entity框架中的DbMigrationsConfiguration。 You might need something like this in your global asx file: 您可能需要在全局asx文件中使用以下内容:

    Database.SetInitializer(new MigrateDatabaseToLatestVersion<YourContext, YourConfiguration>());

Then in your configuration file for migrations you may need something like this: 然后在您的迁移配置文件中,您可能需要以下内容:

    internal sealed class YourConfiguration : DbMigrationsConfiguration<YourContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
    }...

Without more info and code examples, I can only point you in the right direction. 没有更多信息和代码示例,我只能指出正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM