Entity Framework Core遇到的问题汇总
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遇到的问题汇总的更多相关文章
- Entity Framework Core 入门(2)
安装 EF Core 将 EF Core 添加到不同平台和常用 IDE 中的应用程序的所需步骤汇总. 分步入门教程 无需具备 Entity Framework Core 或任何特定 IDE 的原有知识 ...
- Entity Framework Core 1.1 升级通告
原文地址:https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-entity-framework-core-1-1/ 翻译:杨晓东 ...
- Entity Framework Core 实现MySQL 的TimeStamp/RowVersion 并发控制
将通用的序列号生成器库 从SQL Server迁移到Mysql 遇到的一个问题,就是TimeStamp/RowVersion并发控制类型在非Microsoft SQL Server数据库中的实现.SQ ...
- UWP开发之ORM实践:如何使用Entity Framework Core做SQLite数据持久层?
选择SQLite的理由 在做UWP开发的时候我们首选的本地数据库一般都是Sqlite,我以前也不知道为啥?后来仔细研究了一下也是有原因的: 1,微软做的UWP应用大部分也是用Sqlite.或者说是微软 ...
- 全自动迁移数据库的实现 (Fluent NHibernate, Entity Framework Core)
在开发涉及到数据库的程序时,常会遇到一开始设计的结构不能满足需求需要再添加新字段或新表的情况,这时就需要进行数据库迁移. 实现数据库迁移有很多种办法,从手动管理各个版本的ddl脚本,到实现自己的mig ...
- Entity Framework Core 1.1 Preview 1 简介
实体框架核心(EF Core)是Entity Framework的一个轻量级,可扩展和跨平台版本. 10月25日,Entity Framework Core 1.1 Preview 1发布了. 升级到 ...
- 创建ASP.NET Core MVC应用程序(3)-基于Entity Framework Core(Code First)创建MySQL数据库表
创建ASP.NET Core MVC应用程序(3)-基于Entity Framework Core(Code First)创建MySQL数据库表 创建数据模型类(POCO类) 在Models文件夹下添 ...
- 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 ...
- 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 ...
随机推荐
- 在linux下执行git clone、git pull 、git push等操作免密
1. 通过ssh密钥实现 ssh-keygen -t rsa -C "你的邮箱" -f "自己定义的目录" 打开: id_rsa.pub ,将文件内容复制到 g ...
- lrzsz-神一样的上传下载工具
yum list lrzsz rz sz filename
- Java POI 读取Excel数据转换为XML格式
1.首先要下载poi相关的包:http://poi.apache.org/ ,以下是所需的jar包 2.贴上详细的代码 public class ExcelToXml { /** * 将excel的 ...
- Java并发编程详解读书笔记(一)
一.线程介绍 讲线程之前得先了解进程(Peocess),现在的操作系统基本都支持多任务的进行,举个场景:有许多的程序员们喜欢边coding边听点轻音乐.这时计算机就是做并行任务,也就是有多个进程在同时 ...
- logback-spring.xml配置
logback-spring.xml配置 <?xml version="1.0" encoding="UTF-8"?> <configurat ...
- Gym101635K Blowing Candles
题目链接:http://codeforces.com/gym/101635 题目大意: 推荐一篇文章:https://blog.csdn.net/wang_heng199/article/detail ...
- 一文读懂Java注解
什么是注解 Java官方文档上说,注解是元数据的一种形式,它提供不属于程序一部分的数据,注解对被注解的代码没有直接的影响. 准确上说,注解只不过是一种特殊的注释而已,如果没有解析它的代码,它可能连注释 ...
- PHP 调用qq邮箱接口
html代码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <ti ...
- cp: 无法创建普通文件 : 文件已存在
背景 碰到一个偶现的编译出错问题,如图 报错的信息是 cp: 无法创建普通文件"xxx": 文件已存在 排查原因 看了下 Makefile,这句非常简单,就是 cp ./xxx . ...
- Java的四种权限修饰符
private:仅对本类可见 缺省(不需修饰符):对本包可见 protected:对本包及所有子类可见 public:对所有类可见 修饰符: * 权限修饰符:private,默认的,protected ...