简体   繁体   中英

Code-first migration in Entity Framework Core error

I am a .NET student. So please be patient with me. Apart from adding this question here I search web tirelessly to find a solution to my problem. Thank you for understanding.

I am trying to migrate a code-first project with Entity Framework Core just so I can familiarize my self with all the commands and procedures.

The problem I am getting is when a try to migrate. I am writing the line

add-migration Initial-Migration -context BlogContext

in the Package Manager Console. The error I am getting is this one:

错误信息

These are my dependencies:

{
  "dependencies": {
    "BundlerMinifier.Core": "2.2.306",
    "EntityFramework.Core": "7.0.0-rc1-final",
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.2",
    "Microsoft.AspNetCore.Diagnostics": "1.1.0",
    "Microsoft.AspNetCore.Mvc": "1.1.0",
    "Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Routing": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.AspNetCore.StaticFiles": "1.1.0",
    "Microsoft.EntityFrameworkCore": "1.1.0",
    "Microsoft.EntityFrameworkCore.Design": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.Extensions.Logging.Debug": "1.1.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
    "Microsoft.NETCore.App": {
      "version": "1.1.0",
      "type": "platform"
    },
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0"
  },

  "tools": {
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final"
  },

Tell me if there is anything more you would like to see. I am grateful for all the help I get.

EDIT:

My BlogContext: BlogContext

New error from VS Package manager Console:

在此处输入图片说明

  1. Remove "EntityFramework.Core": "7.0.0-rc1-final", dependency (line 3 in listing) - it's old version of Microsoft.EntityFrameworkCore and it may add some old/undesired libs to you app

  2. Run dotnet restore from command line (from src/Blogg folder) to refresh package list (VS should do it automatically, but we need to be sure).

  3. Manually remove bin and obj folders

  4. Run dotnet ef migrations add BlogContext from command line (from src/Blogg folder)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM