0

Is there a way to ignore errors when running a manual migration?

We have client databases in different states and I need to get them all updated to the latest version.

The reason I ask about ignoring errors is because I just want to code my migration like this

    public override void Up()
    {   
        AddColumn("ClientUser", "LastSyncTime", c => c.Guid());
        AddColumn("ClientUser", "FileTransferToken", c => c.Guid());
        AddColumn("ClientUser", "DateFileTransferTokenIssued", c => c.DateTime());
    }

but naturally and expectedly it will throw an exception where the column already exists.

4

2 回答 2

2

不,它不是 EF 迁移的假定用例。迁移将数据库从一个定义的状态驱动到另一个定义的状态。如果您有不同状态的数据库,则需要多次迁移,每个迁移仅涵盖过渡的一部分。

如果您想开始在具有多个数据库的现有项目中使用迁移,您应该首先将所有数据库移动到没有迁移的相同状态并开始将其用作初始状态,之后所有更改将仅通过迁移处理。否则你会遇到很多问题。

于 2012-04-20T11:35:12.473 回答
0

这不能回答您的具体问题,但它可能是您问题的答案。

使用 VS 2010 中的数据库项目来创建目标数据库的架构。

您可以使用此“黄金标准”模式来比较处于不同状态的其他数据库并生成增量脚本以将其从当前模式转移到目标模式。

一旦您在数据库中处于已知状态,然后切换到数据库迁移以向前推进模式。

基思

于 2012-04-20T15:19:08.727 回答