2017-08-22 181 views
3

剛剛開始學習dot net core 2.0。ef-core添加遷移不起作用

當我嘗試創建遷移:

PM> Add-Migration InitialModel 

我得到錯誤:

Add-Migration : Exception calling "Substring" with "1" argument(s): "StartIndex cannot be less than zero. Parameter name: startIndex" At line:1 char:1 + Add-Migration InitialModel + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Add-Migration], MethodInvocationException + FullyQualifiedErrorId : ArgumentOutOfRangeException,Add-Migration

我DOTNET --info

.NET Command Line Tools (2.0.0)

Product Information: Version: 2.0.0 Commit SHA-1 hash: cdcd1928c9

Runtime Environment: OS Name: Windows OS Version: 10.0.15063 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.0.0\

Microsoft .NET Core Shared Framework Host

Version : 2.0.0 Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

我的csproj文件:

<PropertyGroup> 
    <TargetFramework>netcoreapp2.0</TargetFramework> 
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> 
    <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion> 
    <IsPackable>false</IsPackable> 
    </PropertyGroup> 

    <ItemGroup> 
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /> 
    <PackageReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" /> 
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" /> 
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" /> 
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" /> 
    </ItemGroup> 

    <ItemGroup> 
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /> 
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> 
    </ItemGroup> 

感謝您的幫助!

+0

請參閱[this](https://stackoverflow.com/questions/44178411/error-in-migrations-in-efcore)? –

+0

嗯......這個問題應該在2.0.0中解決。 @ user3373603你能否[提交新問題](https://github.com/aspnet/EntityFrameworkCore/issues/new)? – bricelam

+2

@bricelam好吧,我會創建問題,因爲解決方法我添加遷移與開發人員命令提示符'dotnet ef migrations add' – user3373603

回答

1

我所看到的,如果PMC(包管理器控制檯)遷移命令的版本1.x版本的Visual Studio中加載,然後嘗試進行鍼對版本2.x應用程序的命令會出現此錯誤。例如。如果您創建或打開ASP.NET Core 1.1應用程序,然後在同一個Visual Studio會話中創建ASP.NET Core 2.0應用程序。

此案例的解決方法是在使用2.0應用程序之前重新啓動Visual Studio。

根據bricelam NuGet中有一種機制會導致PMC命令的新版本加載到Visual Studio中,但不幸的是,在所有情況下都不會觸發該機制。

+0

我不相信實際上工作.... – DaImTo