Enable -migration not working

I am taking ASP.Net MVC (vidly) course.

I am trying to use migration for the database but it does not work. When I type enable - migration, it gives me

enable : The term ‘enable’ is not recognized as the name of a cmdlet,

this error.

Same thing for add

add : The term ‘add’ is not recognized as the name of a cmdlet,

I can’t really move on without initiating database with migration so I need help asap.

Thank you for help in advance.

Hey, be sure that you install EntityFramework.

 Install-Package EntityFramework -Version 6.4.4

Then make a class in models called ApplicationDbContext
And lastly enable migrations with this line of code

enable-migrations -contexttypename ApplicationDbContext

It should work

I’m having the same issue. I followed your steps but when I get to the last step of enable-migrations -contextypename ApplicationDB Context I get…
PM> enable-migrations -contexttypename ApplicationDbContext
The context type ‘ApplicationDbContext’ was not found in the assembly ‘2VidlyEx1’.

Any advice?

OK here goes…

  1. From the Tools menu, choose NuGet Package Manager , and then choose Package Manager Console .
  2. In the Package Manager Console window, enter the following command:
    Install-Package EntityFramework
    3.Create the DbContext
    in the models folder add a class called ApplicationDbContext paste in the following:
    using System.Data.Entity;
    using System.Data.Entity.ModelConfiguration.Conventions;

namespace Vidly.Models
{
public class ApplicationDbContext:DbContext
{
public DbSet Movies { get; set; }
public DbSet Customers { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    }
}

}
4. From the Tools menu, select NuGet Package Manager > Package Manager Console .
At the PM> prompt enter the following commands:```
enable-migrations
add-migration InitialCreate

Best wishes as the tutorial is missing key  instructions.  Very disappointing.
2 Likes

Ok after doing all this the reason it didn’t work initially is because I did not change the Authentication to Individual User Accounts when creating the project. If you do this you won’t have the issue I had. See here for more info.
ASP.Net Identity on Visual Studio 2019 - ASP.NET MVC - Code with Mosh Forum

1 Like

Thank you so nmuch for this!

Thanks. This did the trick. I went ahead and copied the IdentityModels file from here: vidly-mvc-5/IdentityModels.cs at 638c50c6bd42e356cef39706699429aff19be44e · mosh-hamedani/vidly-mvc-5 · GitHub

Then I had to use nuget to add references to Microsoft.AspNet.Identity.Core, Microsoft.AspNet.Identity.Owin, and Microsoft.AspNet.Identity.EntityFramework

I did this by going to the “Enable Migrations” commit here: https://github.com/mosh-hamedani/vidly-mvc-5/commit/638c50c6bd42e356cef39706699429aff19be44e#diff-40d2c8c304920d496124a183a902db7d4bfe33e27acfd6d8719c1134ae12bb90

Yep. Went back to the set up and realized it was set to ‘individual’, so it did scaffold out everything needed :frowning:

If you’re having this issue, then you will face another issue in section 8 (Authentication).

See this thread to resolve: ASP.Net Identity on Visual Studio 2019 - #3 by Nili

Hello, can i Know where did you git the codes for the course I just gitt in but couldn’t find it har set til mosh and no anwser.