EF Core 遷移過程遇到EF Core tools version版本不相符的解決方案


如果你使用命令:

PM> add-migration Inital

提示如下信息時:

The EF Core tools version '2.1.1-rtm-30846' is older than that of the runtime '2.1.4-rtm-31024'

解決方法大致一下幾種:

第一


最近在跟着官方的文檔學習 .NET Core 。 在寫 “創建 Razor 頁面 Web 應用” Demo 中的——“添加模型”這一篇的教程,“添加初始遷移”中遇到 “The EF Core tools version '2.1.1-rtm-30846' is older than that of the runtime '2.1.3-rtm-32065'. Update the tools for the latest features and bug fixes.”這樣的問題。

這個問題是用 PMC 命令做“初始遷移”的時候出現的,找了很多方法都不行,也看了本機安裝的 .NET Core 的版本(dotnet --version,dotnet --info)。

最后解決辦法: 項目文件夾下使用 .NET Core CLI 命令: dotnet ef migrations add Initial dotnet ef database update 完成后運行可以了

第二


編輯你的<項目名稱>.csproj文件

添加以下內容

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.4" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.6" />
  </ItemGroup>

</Project>

然后運行命令:

PM> Update-Package


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM