Questions tagged [entity-framework-migrations]

Migrations is a feature of Entity Framework that provides for detecting changes to a code(or database)-first model, and upgrading the database (or the model) schema based on those changes.

Migrations is a feature of Entity Framework that provides for detecting changes to a code(or database)-first model, and upgrading the database (or the model) schema based on those changes.

  • Code First Migrations have been included in Entity Framework since version 4.3.
  • The Database First Approach provides an alternative to the Code First approach to the Entity Data Model. It creates model codes (classes, properties, DbContext etc.) from the database in the project and those classes become the link between the database and controller.

MSDN Resources

Package Manager Command Reference

http://coding.abel.nu/2012/03/ef-migrations-command-reference/


See for old versions

3211 questions
553
votes
16 answers

EF Migrations: Rollback last applied migration?

This looks like a really common task, but I can't find an easy way to do it. I want to undo the last applied migration. I would have expected a simple command, like PM> Update-Database -TargetMigration:"-1" Instead, all I can come up with is: PM>…
367
votes
17 answers

Reset Entity-Framework Migrations

I've mucked up my migrations, I used IgnoreChanges on the initial migration, but now I want to delete all my migrations and start with an initial migration with all of the logic. When I delete the migrations in the folder and try and Add-Migration…
173
votes
5 answers

Entity Framework - Start Over - Undo/Rollback All Migrations

For some reason, my migrations appear to have been jumbled/corrupted/whatever. I'm at the point where I just want to start over, so is there a way to completely undo all migrations, erase the history, and delete the migration code, so I'm back to…
drzaus
  • 24,171
  • 16
  • 142
  • 201
171
votes
9 answers

Entity Framework Migrations renaming tables and columns

I renamed a a couple entities and their navigation properties and generated a new Migration in EF 5. As is usual with renames in EF migrations, by default it was going to drop objects and recreate them. That isn't what I wanted so I pretty much had…
168
votes
3 answers

Generate full SQL script from EF 5 Code First Migrations

How do I use Entity Framework 5 Code First Migrations to create a full database script from the initial (empty) state to the latest migration? The blog post at MSDN Blog suggests to do this, but it seems to create an empty script: Update-Database…
Matt Wilson
  • 8,159
  • 8
  • 33
  • 55
156
votes
7 answers

Debug code-first Entity Framework migration codes

I'm using Entity Framework code first in my website and I'm just wondering if there is any way to debug the migration codes. You know, like setting breakpoints and stuff like this. I'm using Package Manager Console to update the database using…
148
votes
12 answers

Unable to create an object of type '[DBContext's Name]'. For the different patterns supported at design time

I'm following one of Mosh Hamedani Course on ASP.NET MVC in Udemy. I came across one error while designing my Database using code-first (Entity Framework). At first, I got the error of " No DbContext was found in assembly". After resolving this…
143
votes
31 answers

There is already an object named in the database

Update-Database failed from Package Manager Console. I've used Entity Framework 6.x and code-first approach. Error is "There is already an object named 'AboutUs' in the database." How can I solve this problem? internal sealed class Configuration …
140
votes
28 answers

The term 'Update-Database' is not recognized as the name of a cmdlet

I am using EF5 beta1 and while I was able to run the "Update-Database" before. Now that I shut down Visual Studio, I cannot get it to run. I get the following error: The term 'Update-Database' is not recognized as the name of a cmdlet, function,…
120
votes
29 answers

Your startup project doesn't reference Microsoft.EntityFrameworkCore.Design

I have 2 projects in my solution, I have a project with Entity Framework Core installed: And in the other ASP.NET Web API project I have these packages:
120
votes
13 answers

How to delete and recreate from scratch an existing EF Code First database

I am using EF Code First with EF 5 in VS 2012. I use PM update-database command and I have a simple seed method to fill some tables with sample data. I would like to delete and recreate my x.mdb. The update history seems to be out of sync. If I…
g.pickardou
  • 32,346
  • 36
  • 123
  • 268
114
votes
31 answers

Unable to generate an explicit migration in entity framework

I am adding a new migration but this message shows: Unable to generate an explicit migration because the following explicit migrations are pending: [201203170856167_left]. Apply the pending explicit migrations before attempting to generate a…
Noman Saeed
  • 1,241
  • 2
  • 8
  • 3
113
votes
20 answers

Add migration with different assembly

I am working on a project with ASP.NET CORE 1.0.0 and I am using EntityFrameworkCore. I have separate assemblies and my project structure looks like this: ProjectSolution -src -1 Domain -Project.Data -2 Api …
112
votes
14 answers

add-migration causing a "Could not load assembly" error

Here's what I am looking at PM> Add-Migration AddedSubdivion -StartUpProjectName Data -Verbose Using StartUp project 'Data'. Using NuGet project 'Registry'. Could not load assembly 'Registry'. (If you are using Code First Migrations inside Visual…
PBG
  • 8,944
  • 7
  • 34
  • 48
108
votes
38 answers

EF Core add-migration Build Failed

I have a developer that is getting "Build failed." when running add-migration in a .NET Core EF project, with no explanation of why the build failed. How do you troubleshoot this error? This is what he gets in the Package Manager Console: Additional…
1
2 3
99 100