Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't run code first migrations using migrate.exe

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?

like image 580
thepaulpage Avatar asked Feb 25 '15 16:02

thepaulpage


People also ask

What is migrate exe?

Code First Migrations can be used to update a database from inside visual studio, but can also be executed via the command line tool migrate.exe. This page will give a quick overview on how to use migrate.exe to execute migrations against a database.

How do I enable migrations in Visual Studio?

From the Tools menu, select NuGet Package Manager > Package Manager Console. The enable-migrations command creates a Migrations folder in the ContosoUniversity project, and it puts in that folder a Configuration. cs file that you can edit to configure Migrations.

Where is ef6 exe located?

Get the ef6.exe CLI Tool The ef6.exe command line tool is found in the tools/ subfolder of the EntityFramework NuGet package. Because it is a standalone tool and NuGet packages are ZIP files, the executable can be extracted directly from the package in Windows by downloading the package, changing the extension from .


1 Answers

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

like image 102
thepaulpage Avatar answered Oct 10 '22 21:10

thepaulpage