Created an ASP.NET MVC 5 project with Individual User Accounts authentication. Classes were created automatically, the connection string to work with authentication. I added my connection string, my model, my context. Example:

 Модель - book`. `Контекст - Contex 

In the context

 DbSet book {get; set;} 

Trying to enable migration ( enable-migrations ), gives an error

This context is not found in the assembly MVC. To enable migrations for 'MVC.Models.Contex', use Enable-Migrations -ContextTypeName MVC.Models.Contex. To enable migrations for 'MVC.Models.ApplicationDbContext', use Enable-Migrations -ContextTypeName MVC.Models.ApplicationDbContext.

That is, it proposes to enable migration for only one context, but how to enable it for 2 contexts? Suddenly, I plan to change the user model, for example.

  • Change the context type of the authentication to the one you are using. - TheOwl
  • one
    The easiest way is to use one context, the one offered by the autogenerator. You can add the necessary models to it and customize as you like. Have you tried to execute the commands that the studio offered you? Perhaps now you just need to pass the name of the context class as a parameter. - beta-tank

1 answer 1

Since you have several contexts within the project, you must explicitly indicate to the utility with which context you want to work. To do this, add the ContextTypeName parameter to the ContextTypeName

Example of the command to enable migrations:

 Enable-Migrations -ContextTypeName MVC.Models.ApplicationDbContext -MigrationsDirectory DirectoryName