Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Code First Migration Error

I'm new to MVC 4 and entity framework and when I run this command from the package manager console:

Enable-Migrations -ContextTypeName MyFirstMvcApp.Models.InventoryDbContext

Join-Path : Cannot bind argument to parameter 'Path' because it is null.

I get the following error:

Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At D:\GitProjects\MyFirstMvcApp\trunk\packages\EntityFramework.6.0.0-alpha2\tools\EntityFramework.psm1:363 char:27
+     $toolsPath = Join-Path <<<<  $installPath tools
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand

Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At D:\GitProjects\MyFirstMvcApp\trunk\packages\EntityFramework.6.0.0-alpha2\tools\EntityFramework.psm1:392 char:73
+     $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-Path <<<<  $toolsPath EntityFramework.PowerShell.Utility.dll))
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand

You cannot call a method on a null-valued expression.
At D:\GitProjects\MyFirstMvcApp\trunk\packages\EntityFramework.6.0.0-alpha2\tools\EntityFramework.psm1:393 char:50
+     $dispatcher = $utilityAssembly.CreateInstance <<<< (
    + CategoryInfo          : InvalidOperation: (CreateInstance:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At D:\GitProjects\MyFirstMvcApp\trunk\packages\EntityFramework.6.0.0-alpha2\tools\EntityFramework.psm1:426 char:19
+         (Join-Path <<<<  $runner.ToolsPath EntityFramework.PowerShell.dll),
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand

How do I fix this? Note that I am using Visual Studio 2010 Ultimate with SP1 and I have installed MVC4 in this link.

like image 763
Rafferty Avatar asked Jan 19 '13 04:01

Rafferty


People also ask

How do I code my first migration to an existing database?

Run the Add-Migration InitialCreate command in Package Manager Console. This creates a migration to create the existing schema. Comment out all code in the Up method of the newly created migration. This will allow us to 'apply' the migration to the local database without trying to recreate all the tables etc.

How do I enable migration in Entity Framework?

Open the Package Manager Console from Tools → Library Package Manager → Package Manager Console and then run the enable-migrations command (make sure that the default project is the project where your context class is).


4 Answers

Fixed it by uninstalling and re-installing entity framework. For the benefit of others, here are the commands...

Uninstall:

PM> Uninstall-Package EntityFramework -Force

After uninstalling, reinstall EntityFramework:

PM> Install-Package EntityFramework -Pre

There! It's fixed. Though I still don't know what caused the problem.

like image 147
Rafferty Avatar answered Oct 05 '22 13:10

Rafferty


Visual studio 2019: Uninstall-Package EntityFramework -Force

then

Install-Package EntityFramework -Pre -Version 6.2.0

something is up with v6.3.0

like image 31
Ayson Baxter Avatar answered Oct 05 '22 14:10

Ayson Baxter


I was facing the same issue this is how I solved the issue,

I'm using Visual Studio 2019 and hence I installed latest Entity framework 6.3.0(stable) I was facing the issue when I run the Enable-Migrations command, I tried to re-install the Entity framework but it didn't work so I have installed the old version 6.2.0 from the Nuget package manger apparently it turned out working.

like image 41
RAGHAVENDRA Avatar answered Oct 05 '22 14:10

RAGHAVENDRA


Tried all the things here. I personally hate solving things without knowing what the problem is in the first place. Digging down in forums this seems to be a known bug caused in version 6.3.0 when the startup project is a web app. They have already fixed it in their daily builds. So to solve it you need to install that.

First, uninstall the package:

PM> Uninstall-Package EntityFramework -Force

Then install the latest daily build (in my case the following one)

PM> Install-Package EntityFramework -Version 6.4.0-preview1-19506-01
like image 38
Nemesis Avatar answered Oct 05 '22 13:10

Nemesis