Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package Manager Console crashes when using Add-Migration

I am using Package Manager Console to add migrations to my database and for some reason it just freezes and does nothing. The only way to stop it and continue using it is to close down Visual Studio using the Task Manager. Is this a known issue?

like image 886
Sachin Kainth Avatar asked Nov 07 '12 15:11

Sachin Kainth


People also ask

Why add-migration is not working?

add-migration : The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

What happens when an add-migration command is executed?

Add-Migration: Creates a new migration class as per specified name with the Up() and Down() methods. Update-Database: Executes the last migration file created by the Add-Migration command and applies changes to the database schema.

What happens when an add-migration command is executed in the NuGet Package Manager console?

Add-Migration Adds a new migration. Remove-Migration Removes the last migration. Scaffold-DbContext Scaffolds a DbContext and entity type classes for a specified database. Script-Migration Generates a SQL script from migrations.

How do I get rid of migration in Visual Studio?

Delete your Migrations folder. Create a new migration and generate a SQL script for it. In your database, delete all rows from the migrations history table. Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there.


1 Answers

I'm not sure if this is a known issue, but I had the same problem, and found a solution for it.

I had to run:

Enable-Migrations -ContextTypeName MyContext -ProjectName MyProject.Framework -StartUpProjectName MyProject.Web

Where I specified:

  • -ContextTypeName as the name of my context
  • -ProjectName as the project that held my Context file
  • -StartUpProjectName as the project that held the web application.

You can reference this resource for more information: http://coding.abel.nu/2012/03/ef-migrations-command-reference/

like image 67
Sean Keating Avatar answered Oct 25 '22 16:10

Sean Keating