【问题标题】:Code first migration into production database代码优先迁移到生产数据库
【发布时间】:2016-06-21 15:31:40
【问题描述】:

我有两个数据库,DEV 和 TEST。

DEV 由我维护,过去几周我一直在使用代码优先迁移进行开发。

TEST 由希望提供 SQL 脚本以将数据库更新到最新版本的 DBA 管理。

这是我第一次在这种情况下首先使用代码,我假设我需要使用命令

Update-Database -Script 

然而事情并没有那么简单。

我正在寻找一种方法来指定上次应用到数据库的迁移。

例如,我有编号为 v1.0、1.1、1.2、1.3、1.4 等的迁移

我知道 TEST 当前正在运行 v1.2 并且 DEV 在 1.6 上,我想将 TEST 更新到 1.5(请注意,这不是最新版本)构建该脚本的命令是什么?

我试过了

update-database -Script -TargetMigration "v1.5" 

但是,这将迁移 1.5 与我的 DEV 数据库进行比较,这给了我一个脚本,该脚本从 v1.6 回滚到 1.5,而不是更新到 1.6 的脚本

我知道我可以将项目中的连接字符串更改为指向 TEST 数据库,然后运行命令,但这似乎是一种解决方法 - 必须有一种方法可以指定从什么迁移开始以及什么迁移脚本最多?

理想情况下,我不想将我的开发数据库回滚到与 TEST 相同的版本。

【问题讨论】:

    标签: database ef-code-first entity-framework-6


    【解决方案1】:

    如果您在包管理器控制台中运行以下命令,您将获得 Update-Database 命令的详细帮助:

    get-help Update-Database -detailed
    

    从那里你可以看到参数,我认为这就是你所需要的。

    -SourceMigration <String>
        Only valid with -Script. Specifies the name of a particular migration to use
        as the update's starting point. If omitted, the last applied migration in
        the database will be used.
    
    -TargetMigration <String>
        Specifies the name of a particular migration to update the database to. If
        omitted, the current model will be used.
    

    【讨论】:

    • 正是我需要的。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 2018-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-15
    相关资源
    最近更新 更多