1

I am using Entity Framework 5 RC, code first. I am struggling with migrating databases that were created on different versions of code. For example, Database A was created when table FooBar didn't exist. Database B was created after table FooBar was added to my model.

I have a migration written that adds the FooBar table. Is it my responsibility to check in the FooBar migration that the table doesn't exist before calling CreateTable? It seems that is the case since Database B doesn't have an entry for the FooBar migration and will attempt to run it.

At first the MigrationHistory table seemed like it would save me from adding these checks but since new databases won't have entries for migrations added before the database was created, I still need to do the checks myself. Is that the right way to go about it or am I missing something?

4

1 回答 1

0

为了解决我在添加存储过程时遇到的问题,我编写了一个 TSQL 脚本来创建一个新表“_PreviousMigrationHistory”——它在我的存储过程脚本运行后从“_MigrationHistory”表中接收新条目......

我确实向两个表(INT - IDENTITY(1,1) 的“VersionId”)添加了一个新列,这是我在代码中用于比较的列。

这样,即使发生 Code First 迁移,您也可以使用未更新的迁移模式 (__PreviousMigrationHistory)。

这会有帮助吗?

**编辑 - 抱歉,我想念这个问题。- 虽然我认为数据库的新实例仍会经历迁移步骤,这反过来应该将条目添加到 __MigrationHistory 表中?

于 2013-10-11T14:27:43.780 回答