c# - 无法使用 migrate.exe 运行代码优先迁移

标签 c# entity-framework code-first

我正在尝试更新测试系统上的数据库。当我运行 update-database在 visual studio 中,事情按预期工作。

当我部署然后尝试在测试机器上运行时:

Migrate.exe CodeFirst.dll /startupConfigurationFile="..\web.config"

我得到:

no connection string named xxx could be found in the application config file

...即使在 web.config 中有一个具有该名称的连接字符串。只有一个 .config 文件,没有我正在运行的 dll 的配置文件

我试图手动声明我的连接字符串:

Migrate.exe CodeFirst.dll /connectionString="Data Source=192.168...;Initial Catalog=Database;" /connectionProviderName="System.Data.SqlClient"

但由于某种原因仍然给出相同的错误...它是否忽略了我传入的连接字符串并试图再次寻找一个?为什么要这样做?

但这给了我一个非常奇怪的错误:

The migrations configurations type "Source=192.168... could not be found in the assembly CodeFirst.dll I wondered if it had something to do with spaces, so I tried changing 'data source' to 'server' and Initial Catalog to 'database' but that didn't help.

编辑:固定引号

我见过类似的问题,但它们都是关于在 visual studio 中运行的,我在尝试这样做时没有遇到任何问题。关于我能做什么的更多想法?有没有人得到这些选项中的任何一个?

最佳答案

终于让它与 Entity Framework 6.1.3 一起工作。我不确定版本是否真的很重要,但我们最终下载了代码并针对它进行了调试。

真正不同的是在所需的两个路径中都使用了完整路径......希望可以帮助别人!

migrate CodeFirst.dll Configuration /startUpDirectory:"C:\src\app\CodeFirst\bin\Debug" /startUpConfigurationFile:"C:\src\app\CodeFirst\bin\CodeFirst.dll.config" 

我联系了 EF 团队,显然 EF7 中的情况会更好:https://github.com/aspnet/EntityFramework/issues/2974

关于c# - 无法使用 migrate.exe 运行代码优先迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28724546/

相关文章:

c# - StackPanel 的 MouseWheel EventToCommand

c# - 使用 SYSTEMTIME 在 24 模式下更改日期和时间

c# - 检查多个项目是否存在的最有效方法

c# - EntityHydrate 任务失败

c# - 您可以使用 Entity Framework 4.1 代码优先方法创建 sql View /存储过程吗

c# - 将代码注入(inject)所有没有自定义属性的方法和属性的最简单方法

c# - 如何将透明光标渲染到保留 alpha channel 的位图?

.net - 数据库架构更改是否会破坏实体的 linq

entity-framework - 启用代码优先迁移时在 Web.config 中使用连接字符串

entity-framework - Entity Framework 和带有显式链接表的多对多关系