Can't run code first migrations using migrate.exe

c# code-first entity-framework

Question

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:

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

...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:

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.

edit: fixed quotation marks

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?

1
15
2/25/2015 5:01:57 PM

Accepted Answer

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" 

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

30
2/4/2016 3:02:58 PM

Popular Answer

Those of us just starting to use this tool might find this PowerShell script useful - it contains some default values for some common use cases:

Param(
    [string]$DbConnectionString,
    [string]$StartUpDirectory,
    [string]$DataModelDllName,
    [string]$StartUpConfigurationFile = "$StartUpDirectory\$DataModelDllName.config",
    [string]$ConfigurationClassName = "Configuration",
    [string]$ConnectionProviderName = "System.Data.SqlClient",
    [string]$MigrateToolPath = "$PSScriptRoot\migrate.exe"
)

& $MigrateToolPath $DataModelDllName $ConfigurationClassName /startUpConfigurationFile=$StartUpConfigurationFile /connectionString=$DbConnectionString /connectionProviderName=$ConnectionProviderName  /startUpDirectory=$StartUpDirectory


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow