Migration - Targeting Different Context Files (Areas.Data...)

Dean Everhart 1,496 Reputation points
2023-04-13T17:27:49.5433333+00:00

Errors:

PM> add-migration CreateIdentitySchema
Build started...
Build succeeded.
More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.
PM> add-migration CreateIdentitySchema -AuthenticationTutorial1Context
Add-Migration : A parameter cannot be found that matches parameter name 'AuthenticationTutorial1Context'.
At line:1 char:36
+ add-migration CreateIdentitySchema -AuthenticationTutorial1Context
+                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Add-Migration], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Add-Migration
 
PM> add-migration CreateIdentitySchema -Areas.Identity.Data.AuthenticationTutorial1Context
Add-Migration : A parameter cannot be found that matches parameter name 'Areas'.
At line:1 char:36
+ add-migration CreateIdentitySchema -Areas.Identity.Data.Authenticatio ...
+                                    ~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Add-Migration], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Add-Migration

Project Name: AuthenticationTutorial1 on GitHub Tutorial: Introduction to Identity on ASP.NET Core Step In Tutorial: Migrations

Steps Taken Environment: Net Core 6, Visual Studio Community 2022 (64 bit), WIndows 11

User's image

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,308 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,384 questions
{count} votes

Accepted answer
  1. Zhi Lv - MSFT 32,056 Reputation points Microsoft Vendor
    2023-04-14T01:41:06.24+00:00

    Hi @Dean Everhart

    More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.

    As the error message said, there are more than on DbContext, when running the migration commands, you need to use the the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.
    So, if you want to use the AuthenticationTutorial1Context, the migration commands should like this:

    add-migration CreateIdentitySchema -Context -AuthenticationTutorial1Context
    update-database -Context -AuthenticationTutorial1Context
    

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Best regards,
    Dillion

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. AgaveJoe 26,851 Reputation points
    2023-04-13T18:52:39.79+00:00

    Looks like you created two different DbContext. The command can't read your mind. You must add a command parameter to tell the command which DbContext gets the migration as clearly stated in the error message.

    0 comments No comments