2

I am trying to enable migrations in my project but I always get this error :

More than one context type was found in the assembly 'CarManagement'.
To enable migrations for 'CarManagement.Models.CarManagementContext', use Enable-Migrations

-ContextTypeName CarManagement.Models.CarManagementContext.

To enable migrations for 'CarManagement.Models.ApplicationDbContext', use

Enable-Migrations -ContextTypeName CarManagement.Models.ApplicationDbContext

and when I try to use only one context it also does not work and this error appears:

Enable-Migrations: A positional parameter cannot be found that accepts argument 'CarManagement.Models.CarManagementContext.'.
At line:1 char:1

  • Enable-Migrations -ContextTypeName eManager CarManagement.Models.CarM ...
  •   + CategoryInfo          : InvalidArgument: (:) [Enable-Migrations], ParameterBindingException
      + FullyQualifiedErrorId : PositionalParameterNotFound,Enable-Migrations
    

screenshot of PM to embed

8
  • Show your entire commandline. I think you have a rogue "eManager" somewhere in it. Commented Aug 3, 2017 at 11:28
  • PM> Enable-Migrations More than one context type was found in the assembly 'CarManagement'. To enable migrations for 'CarManagement.Models.CarManagementContext', use Enable-Migrations -ContextTypeName CarManagement.Models.CarManagementContext. To enable migrations for 'CarManagement.Models.ApplicationDbContext', use Enable-Migrations -ContextTypeName CarManagement.Models.ApplicationDbContext. PM> Enable-Migrations -ContextTypeName eManager CarManagement.Models.CarManagementContext. Enable-Migrations : A positional parameter cannot be found that accepts .......... Commented Aug 3, 2017 at 11:33
  • Yeah that doesn't really help. Anyway remove the "eManager" from that. Commented Aug 3, 2017 at 11:33
  • Sorry I will try to take a screenshot, maybe you it will be more clear, what do you mean by eManager ? How can i remove it ? Commented Aug 3, 2017 at 11:37
  • You are using the commandline Enable-Migrations -ContextTypeName eManager CarManagement.Models.CarManagementContext. Remove the "eManager" from that. I don't know where it comes from, but you have typed it. Commented Aug 3, 2017 at 11:46

2 Answers 2

10

I was getting the same error when I was trying to add migration with Add-Migration.

enter image description here

The issue was, as I have had more than one DBContext, I had to specify which one to use. We can either use the '-Context' parameter for PowerShell commands or the '--context' parameter for dotnet commands.

I was using --context in my command instead of -Context as I was running the command in Package Manager Console.

Add-Migration "AddNameColumnFavorites" --context LearnraumDatabaseCon

To fix the issue, I had to change the command as preceding.

Add-Migration -Context LearnraumDatabaseContext "AddNameColumnFavorites" 

Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

1

you're typing a dot at the end of command. Try just:

Enable-Migrations -ContextTypeName CarManagement.Models.ApplicationDbContext

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.