EntityFramework enable-migrations ArgumentException

I am new to the beautiful world of Microsoft Azure and made my first welcome world. The next step is to create the database (entityframework), but I get an exception when creating the database from PackageManagerConsole (PMC). I read several posts on the Internet explaining that I need to add startupprojectname to the PS command, but unfortunately this will not solve my problem.

I have 2 projects in my solution.

  • "partyonwebsite" which is a startup project and obviously my site :).
  • "models" where I will create my models / entities.

In the "models" project, I have the classes "User" and "UsersDb". UsersDb is a class that inherits from DbContext.

Now, when I execute the following line in PMC:

enable-migrations -StartUpProjectName "PartyOnWebsite" -ContextTypeName "Models.Users.UsersDb" 

I get the following (not very useful) error:

 System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) 

I looked at get-help enable-migrations and played a little, but not very lucky.

Has anyone encountered the same problem? Or can you point me in the right direction to help me solve this problem?

Many thanks!

Bas

+2
source share
1 answer

solved. If you encounter the same problem, make sure EntityFramework is configured correctly for your individual Model project.

  • Open Manage NuGet Package Solutions for Solution in the solution browser (right-click in the solution browser)
  • Select Installed Packages
  • Select "EntityFramework" and click "Manage"
  • Check out the โ€œModelsโ€ project (I checked the design of my site and the โ€œmodelsโ€ project).

Run the enable-migrations command again.

I also added a link to the project from my website project to the Models project, I donโ€™t know if that matters.

The command successfully executed after my settings in NuGet:

 enable-migrations -ProjectName Models -ContextTypeName Models.Users.UsersDb 

Hope this answer helps another dead soldier on his way to get his first application working in Lazur :).

Greetings

Bas

+4
source

All Articles