EF 4.3.1 Migration - how to downgrade a production database? - entity-framework

I have been looking at how to produce a downgrade in EF 4.3.1 Migrations, and all I have found is only about scripting (like this EF 4.3 Migration - how to produce a downgrade script?)
To upgrade my user's production database I call the method MigrateDatabaseToLatestVersion<TContext, TMigrationsConfiguration>
upon application startup, so I make sure that all users have the same database schema after they install a new version of my app. I don't need to run any scripts on the client side once the migrations are configured.
What happens if I want to downgrade to a different version? It seems quite obvious that this method only moves Up until it reaches the latest migration... is there something like MigrateDatabaseToVersion<TContext, TMigrationsConfiguration, DbMigration> where the DbMigration object is the target migration?
Can I avoid running a SQL script if I want to downgrade a production database?
Thanks guys!

You could use the migrate.exe tool which comes with EF to go to specific migrations.
Migrate.exe MyApp.exe /startupConfigurationFile=”MyApp.exe.config” /targetMigration=”myTargetMigration”
Docs can be found at: http://msdn.microsoft.com/en-us/data/jj618307.aspx
Edit: How to use a connection string
Migrate.exe whereYourMigrationsAre.dll /connectionString=”Data Source=localhost;Initial Catalog=blah;whatever else you want to set” /connectionProviderName=”System.Data.SqlClient”

Related

How to migrate from MySQL.EntityFrameworkCore to Pomelo.EntityframeworkCore

I've got a production system that I'd like to migrate from using MySQL.EntityframeworkCore to Pomelo.EntityFrameworkCore. I wanted to do some due diligence before I just upgraded the nuget packages and give it a spin. I appreciate any insight. Currently I'm on EF5, also planning on upping to EF6.
One area of concern is existing migrations. Will they be compatible? Early in the project I switched from MSSQL provider to MySQL and had to delete and regenerate the migrations from scratch.

VS2012 and Entity Framework 6.1.3 compatibility

I am using VS2012 and trying to run a code I have received from a colleague (who happens to use VS2013). He is using EF (v 6.1.3) Code-First New Database approach.
Now I am trying to enable the migrations to create the database, but Package Manager Console is unable to identify Enable-Migrations code.
Below is the error I receive (please click the image to enlarge)
I have installed EF Tools for VS2012, but that does't resolve the issue. Even Microsoft tells that it can only resolve EF Code-First Existing Database problems.
I don't know if I have to rollback Microsoft.NETCore.Platforms v1.1.0 to a previous version.
Any help on this is appreciated.
Edit
Error tells that I need a newer Nuget version, but VS2012 doesn't support Nuget v2.12

EF Core 1.1.0 Migrations on other servers (not development)

When development is finished and TFS (VSTS) takes over. The build completes successfully and the artifact directory contains the published website via a build definition. The Release Manager is then triggered, and takes over and creates a website in an environment, the website files are copied to the environment and the website started. All good so far.
Missing the Database migration steps here...
Now someone starts the server and it fails because the database has not been migrated. How do we do that? The EF Tools were not copied to that environment, in fact we can't even run dotnet.exe because the core sdk has not been deployed onto that environment either. so even if we had the tools, we can't execute them.
In EF 6.x it was easy cause we could just copy migrate.exe as part of the artifacts, and run that on the environment after the files were copied. As I understand it, the EF Tools are now a DLL (ef.dll) that has to be run by dotnet.exe. Does this mean that all web servers now need Core SDK to perform migrations?
Other details about my project setup:
asp.net.core application being deployed onto a QA server for testing. This is not a dev box, does not have VS2015 installed, does not have Core SDK installed.
Update: EF.EXE is part of preview3 and 4.
This solves the requirement for "dotnet.exe" being installed. I can copy that into the artifacts drop like I used to with migrate.exe. Is this the proposed solution by the EF Team?
EF.EXE is part of preview3 and 4.
This solves the requirement for "dotnet.exe" being installed. I can copy that into the artifacts drop like I used to with migrate.exe. Is this the proposed solution by the EF Team?
Yes. Do this.
Also see issue #6313 where we want to make this experience a little easier on .NET Core.
In order to run .NET Core web application on your server, you need to install .NET Core SDK (currently 1.1) on your servers. Doing so will give you the dotnet command so that you can execute dotnet ef database update on your server environment to update the database to a specified migration.

WPF using LocalDB doesn't deploy correctly

I've written a program that uses Code First with LocalDB to store data. After using Click Once to deploy, the application doesn't create the LocalDB in production. I've tried all of the Database Initializers, and the app just errors out saying that no tables actually exist.
I'm assuming that there is something simple that I'm missing, but all the articles I find seem to refer to using SQL Express.
Edit
May be related to EF 6.1.1. I've tried downgrading to 5 and it appears to be working, but I'm not done testing yet.
Downgrading EF from 6.1.1 to 5.0.0 has resolved this issue. I can only assume that this is a bug in 6.1.1.

EF (Entity Framework) 4.3 Migration tool does not work on EF 4.1 DB

I want to modify one DB which was developed with EF 4.1 (Code First). I upgraded the project into EF 4.3 and follow this steps:
http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx
Everything is going well, but when I want to test on current DB (EF 4.1 Code First), Update-Database raise this error:
Cannot scaffold the next migration because the target database was
created with a version of Code First earlier than EF 4.3 and does not
contain the migrations history table. To start using migrations
against this database, ensure the current model is compatible with the
target database and execute the migrations Update process. (In Visual
Studio you can use the Update-Database command from Package Manager
Console to execute the migrations Update process).
I was wondering how I can migrate an EF 4.1 (Code First) DB? Moreover that DB is live and has data and I cannot drop tables.
You need to create an empty migration and execute it prior to doing changes to your model. It will create the migration history table for you. After that you can use migrations for new changes. I wrote walkthrough article about this topic.
Run "Add-Migration InitialMigration -IgnoreChanges" before doing any changes to the model.. Make the required changes, then run "update-database"