1.add-migration : 无法将“add-migration”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。

使用Entity Framework Core命令 add-migration manage 出现以下错误

PM> add-migration manage
add-migration : 无法将“add-migration”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
所在位置 行: 字符:
+ add-migration manage
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (add-migration:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

使用EF core命令需要安装迁移用的库 Microsoft.EntityFrameworkCore.Tools ,所以在nuget 添加 Microsoft.EntityFrameworkCore.Tools包 或者 输入 Install-Package Microsoft.EntityFrameworkCore.Tools

2.System.NullReferenceException: Object reference not set to an instance of an object.

删除model中的一个属性,然后提交 Add-Migration ,返回以下错误:

PM> Add-Migration ModifyCitys
Build started...
Build succeeded.
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Initialize(ColumnOperation columnOperation, IProperty property, CoreTypeMapping typeMapping, Boolean isNullable, IEnumerable` migrationsAnnotations, Boolean inline)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Add(IProperty target, DiffContext diffContext, Boolean inline)+MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable` sources, IEnumerable` targets, DiffContext diffContext, Func` diff, Func` add, Func` remove, Func`[] predicates)+MoveNext()
at System.Linq.Enumerable.ConcatIterator`.MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(ITable source, ITable target, DiffContext diffContext)+MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable` sources, IEnumerable` targets, DiffContext diffContext, Func` diff, Func` add, Func` remove, Func`[] predicates)+MoveNext()
at System.Linq.Enumerable.ConcatIterator`.MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Sort(IEnumerable` operations, DiffContext diffContext)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDifferences(IModel source, IModel target)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Object reference not set to an instance of an object.

用的EF版本

EF Core version:5.0.0-preview.2.20120.8
Database provider: Microsoft.EntityFrameworkCore.SqlServer 5.0.0-preview.2.20120.8

3.1.2版本没有问题,已提交issues

https://github.com/dotnet/efcore/issues/20348

3.More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.

由于使用多个DbContext,在使用命令生成数据库文件没有指定DbContext

在原命令add-migration 后加上-c DbContext的类名

4.Unable to create an object of type 'MyDBContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

PM> Add-Migration Initial
Build started...
Build succeeded.
Unable to create an object of type 'MyDBContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

参考:

https://www.cnblogs.com/wyy1234/archive/2018/09/18/9670529.html

https://www.cnblogs.com/wyy1234/p/9647730.html

https://blog.csdn.net/xingkongtianyuzhao/article/details/104216879

Entity Framework Core遇到的问题汇总的更多相关文章

  1. Entity Framework Core 入门(2)

    安装 EF Core 将 EF Core 添加到不同平台和常用 IDE 中的应用程序的所需步骤汇总. 分步入门教程 无需具备 Entity Framework Core 或任何特定 IDE 的原有知识 ...

  2. Entity Framework Core 1.1 升级通告

    原文地址:https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-entity-framework-core-1-1/ 翻译:杨晓东 ...

  3. Entity Framework Core 实现MySQL 的TimeStamp/RowVersion 并发控制

    将通用的序列号生成器库 从SQL Server迁移到Mysql 遇到的一个问题,就是TimeStamp/RowVersion并发控制类型在非Microsoft SQL Server数据库中的实现.SQ ...

  4. UWP开发之ORM实践:如何使用Entity Framework Core做SQLite数据持久层?

    选择SQLite的理由 在做UWP开发的时候我们首选的本地数据库一般都是Sqlite,我以前也不知道为啥?后来仔细研究了一下也是有原因的: 1,微软做的UWP应用大部分也是用Sqlite.或者说是微软 ...

  5. 全自动迁移数据库的实现 (Fluent NHibernate, Entity Framework Core)

    在开发涉及到数据库的程序时,常会遇到一开始设计的结构不能满足需求需要再添加新字段或新表的情况,这时就需要进行数据库迁移. 实现数据库迁移有很多种办法,从手动管理各个版本的ddl脚本,到实现自己的mig ...

  6. Entity Framework Core 1.1 Preview 1 简介

    实体框架核心(EF Core)是Entity Framework的一个轻量级,可扩展和跨平台版本. 10月25日,Entity Framework Core 1.1 Preview 1发布了. 升级到 ...

  7. 创建ASP.NET Core MVC应用程序(3)-基于Entity Framework Core(Code First)创建MySQL数据库表

    创建ASP.NET Core MVC应用程序(3)-基于Entity Framework Core(Code First)创建MySQL数据库表 创建数据模型类(POCO类) 在Models文件夹下添 ...

  8. Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 更新关系数据

    Updating related data¶ 7 of 7 people found this helpful The Contoso University sample web applicatio ...

  9. Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 读取关系数据

    Reading related data¶ 9 of 9 people found this helpful The Contoso University sample web application ...

随机推荐

  1. PAT 1028 List Sorting (25分) 用char[],不要用string

    题目 Excel can sort records according to any column. Now you are supposed to imitate this function. In ...

  2. My sql的知识点 不足点请指点谢谢

    My SQL:(关系数据库) 数据库能够能够干吗? 1. :存储大量的信息,方便检索和访问    2. :保持数据信息的一致,完整      3. : 共享和安全 4. : 通过组合分析,产生新的有用 ...

  3. centos7 下安装apache mysql php phpmyadmin。

    1 安装mysql yum -y install mariadb-server systemctl start mariadb.service systemctl enable mariadb.ser ...

  4. React框架概述

    一.React框架概述 官网:https://reactjs.org/       最新版V16.10 中文网:https://zh-hans.reactjs.org/ 中文社区网:https://r ...

  5. 10 分离式web框架

    10 分离式web框架 wsgiref模块: 将http请求封装成以键值对的形式封装成字典environ: "PATH_INFO"对应的值为请求文件路径, “QUERY_STRIN ...

  6. zabbix 自动发现主机并关联模板

    一.自动发现添加主机 1.利用agent自动发现主机 Configuration - Discovery -Create discovery rule 2.将自动发现的主机关联模板 Configura ...

  7. Educational Codeforces Round 56 (Rated for Div. 2) F. Vasya and Array

    题意:长度为n的数组,数组中的每个元素的取值在1-k的范围内或者是-1,-1代表这个元素要自己选择一个1-k的数字去填写,然后要求填完的数组中不能出现连续长度大于len的情况,询问填空的方案数. 题解 ...

  8. HDU2825AC自动机+状压

    //我感觉这题不如叫你不看代码就不知道题干在说啥,强烈吐槽 Liyuan lives in a old apartment. One day, he suddenly found that there ...

  9. poj2778 AC自动机

    以下内容均为转载,,只有代码是自己写的=-= http://blog.csdn.net/morgan_xww/article/details/7834801   转载地址 博主写的很好 ------- ...

  10. Ant Design of Vue 组件库的使用

    文档里面很清楚 安装步骤    这是全部引入的 1  有的组价涉及到汉化的问题 import moment from 'moment' import '../../../../node_modules ...