今天使用了一下EF Core的Code First,进行数据库迁移的的时候报错了:数据库
The specified framework version '2.1' could not be parsed框架
解决方法:在DbContext的csporj工程文件里指定一下运行时框架3d
<RuntimeFrameworkVersion>2.1.6</RuntimeFrameworkVersion>blog
添加完成后再次运行迁移指令:dotnet ef migrations add <记录名>继承
结果又爆出了新的错误接口
Unable to create an object of type 'EFDbContext'. Add an implementation of 'IDesignTimeDbContextFactory<EFDbContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.ci
出现这种错误是由于Dbcontext没有在Web项目里面,因此他找不到连接字符串,没办法实例化DbContext字符串
解决方案:咱们在Dbcontext的同级目录新建一个类DesignTimeDbContextFactoryget
让这个类继承IDesignTimeDbContextFactory接口it
写完后再次执行迁移指令,发现迁移成功
出现这种问题,我我的认为应该是个人DbContext没有建到Web项目下的缘由,我以为若是引入一下Nuget的Asp.NETMVC包应该也能解决问题,不过我就不去试了哈哈哈哈哈