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. java -> StringBuffer与StringBuilder类

    字符串缓冲区 StringBuffer类 在学习String类时,API中说字符串缓冲区支持可变的字符串,什么是字符串缓冲区呢?接下来我们来研究下字符串缓冲区. 查阅StringBuffer的API, ...

  2. 我的linux学习日记day2

    RPM  软件包管理器 目的:降低软件安装难度原理 :将软件源代码加上一套安装规则打包到一起,用户只需要运行RPM systemctl start 服务名称 开启服务systemctl stop 服务 ...

  3. centos7 下安装apache mysql php phpmyadmin。

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

  4. 【雕爷学编程】Arduino动手做(47)---七段LED数码管模块

    37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器和模块,依照实践(动手试试)出真知的理念,以学习和交流为目的,这里准备 ...

  5. vue 细节注意

    *只有vm.$data这些被代理的属性是响应的,能够重新渲染视图 *注意,不要在实例属性或者回调函数中(如 vm.$watch('a', newVal => this.myMethod()))使 ...

  6. Django之ORM中事务和锁

    ORM事务: 事务: 数据库事务(简称:事务)是数据库管理系统执行过程中的一个逻辑单位,由一个有限的数据库操作序列构成. 事务的特点: 并非任意的对数据库的操作序列都是数据库事务.数据库事务拥有以下四 ...

  7. win10安装nodejs,修改全局依赖位置和环境变量配置

    为什么要修改nodejs全局依赖位置? nodejs全局依赖安装默认位置在C盘,导致C盘文件太大,影响电脑运行速度. 步骤: 安装nodejs(在node官网下载并安装) 查看nodejs版本(在命令 ...

  8. unicode 的中文字符串,调用 isalnum()返回的是 True ?

    描述 Python isalnum() 方法检测字符串是否由字母和数字组成. 语法 isalnum()方法语法: str.isalnum() 返回值 如果 string 至少有一个字符并且所有字符都是 ...

  9. element-ui上传组件,通过自定义请求上传文件

    记录使用element-ui上传组件,通过自定义请求上传文件需要注意的地方. <el-upload ref="uploadMutiple" :auto-upload=&quo ...

  10. python的转义

    print('"I\'m OK"') print("I'm OK") print('"I"\'m \"OK"') &qu ...