我有使用Entity Framwork 4.3及其迁移的ASP.NET MVC 3项目。现在我希望实体框架为我创建一个使用我已有的迁移的数据库。 当我尝试运行更新的数据库的脚本,它给了我下面的:如何使用代码优先迁移创建数据库?
Update-Database -Verbose -ProjectName AssemblyWithMigrations -StartUpProjectName WebProjectAssembly No migrations configuration type was found in the assembly '/* my name of assembly */'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
但是,当我试图运行Enable-Migrations
我看到以下内容:
Migrations have already been enabled in project 'AssemblyWithMigrations '. To overwrite the existing migrations configuration, use the -Force parameter.
所以,问题是EF试图解决当前的迁移版本来更新数据库,我想。但数据库不存在,它显然失败。
问题是:如何使用EF迁移创建数据库,如果它不存在?或者,使用Nuget控制台的正确方法是什么?
综上所述,我想: 1.运行命令(也许update-database
),将使用我的web.config文件 2.所有迁移将创建的数据库在其创建顺序应用创建数据库。
谢谢。 :)
我不认为迁移只是为了创建数据库来更新它们。 –
如果数据库不存在,'Update-Database'会自动创建并应用每个迁移。你有任何额外的信息?在同一个项目中不应该发生“找不到迁移配置类型”和“迁移已启用”。 – bricelam