无法使用migrate.exe运行代码优先迁移 [英] Can't run code first migrations using migrate.exe

查看:86
本文介绍了无法使用migrate.exe运行代码优先迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在测试系统上更新数据库。当我在Visual Studio中运行更新数据库时,一切正常。

I'm trying to update a database on a test system. When I run update-database in visual studio things work as expected.

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

When I deploy and then try to run on a test machine:

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

I get:


在应用程序配置文件中找不到名为xxx的连接字符串

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

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

...even though there is a connection string with that name in the web.config. There is only one .config file, there isn't a config file for the dll that I'm running against

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

I attempted to declare my connection string manually:

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

,但是由于某些原因,仍然给出相同的错误...是否忽略我传入的连接字符串并尝试再次查找?

but that still gave the the same error for some reason... Is it ignoring the connection string that I'm passing in and trying to look for one again? Why would it do that?

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

but that gave me a really weird error:


在程序集CodeFirst.dll
中找不到
的迁移配置类型 Source = 192.168 ...,我想知道它是否与空格有关,因此我尝试更改'数据源到服务器,初始目录到数据库,但这没有帮助。

编辑:固定引号

我也遇到过类似的问题,但它们都是关于在Visual Studio中运行的问题,尝试这样做时我没有任何问题。我可以吗?有没有人能使用这些选项中的任何一个?

I've seen similar questions but they were all about running inside of visual studio and I have no issues when trying to do that. Any more ideas of what I can do? Has anyone gotten either of these options to work?

推荐答案

最后使它与Entity Framework 6.1.3一起使用了。

Finally got this to work with Entity framework 6.1.3. I'm not sure if the version really matters, but we ended up downloading the code and debugging against that.

真正使我们与众不同的是,使用了其中的完整路径。两者都他需要的路径...希望能帮助到别人!

What really made the difference was using the full path in both of the paths required... Hope that can help someone!

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

I reached out to the EF team, and apparently things will be better in EF7: https://github.com/aspnet/EntityFramework/issues/2974

这篇关于无法使用migrate.exe运行代码优先迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆