【问题标题】:ef-core Add-Migration not workingef-core 添加迁移不起作用
【发布时间】:2018-01-24 04:21:51
【问题描述】:

刚开始学习dot net core 2.0。

当我尝试创建迁移时:

PM> Add-Migration InitialModel

我得到错误:

添加迁移:使用“1”参数调用“子字符串”的异常: “StartIndex 不能小于零。参数名称:startIndex”在 行:1 字符:1 + 添加迁移 InitialModel + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Add-Migration], MethodInvocationException + FullyQualifiedErrorId : ArgumentOutOfRangeException,Add-Migration

我的 dotnet --info

.NET 命令行工具 (2.0.0)

产品信息:版本:2.0.0 提交 SHA-1 哈希: cdcd1928c9

运行时环境:操作系统名称:Windows 操作系统版本:10.0.15063 操作系统平台:Windows RID:win10-x64 基本路径:C:\Program 文件\dotnet\sdk\2.0.0\

Microsoft .NET Core 共享框架主机

版本:2.0.0 构建: 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>

感谢您的帮助!

【问题讨论】:

  • this?
  • 嗯...这个问题应该在 2.0.0 中修复。 @user3373603 你能submit a new issue吗?
  • @bricelam 好的,我将创建问题,作为解决方法,我使用开发人员命令提示符添加迁移dotnet ef migrations add

标签: .net-core entity-framework-core entity-framework-migrations


【解决方案1】:

我发现如果在 Visual Studio 中加载 v1.x 版本的 PMC(包管理器控制台)迁移命令,然后您尝试针对 v2.x 应用程序运行命令,则会出现此错误。例如。如果您创建或打开 ASP.NET Core 1.1 应用程序,然后在同一 Visual Studio 会话中创建 ASP.NET Core 2.0 应用程序。

这种情况的解决方法是在使用 2.0 应用程序之前重新启动 Visual Studio。

根据bricelam 的说法,NuGet 中有一种机制会导致将新版本的 PMC 命令加载到 Visual Studio 中,但不幸的是,并非在所有情况下都会触发该机制。

【讨论】:

    猜你喜欢
    • 2017-05-30
    • 2018-06-08
    • 2018-02-10
    • 2021-12-25
    • 1970-01-01
    • 2017-11-30
    • 2018-11-30
    • 1970-01-01
    • 2017-04-12
    相关资源
    最近更新 更多