关于ASP EntityFramework 启用迁移 Enable-Migrations 报异常 “No context type was found in the assembly”
在尝试进行对原本数据库进行更新并扩展User.Identity的可用属性时,需要启用迁移 Enable-Migrations,在工具》NuGet packge manager 》Package Manager Console中输入Enable-Migrations。
但是如果你的项目中有多个context,直接使用Enable-Migrations就会报错:
More than one context type was found in the assembly ‘yourApplication’.
To enable migrations for ‘yourApplication.Models.ApplicationDbContext’, use Enable-Migrations -ContextTypeName yourApplication.Models.ApplicationDbContext.
To enable migrations for ‘yourApplication.Models.Model1’, use Enable-Migrations -ContextTypeName yourApplication.Models.Model1.
报错信息在提示你需要指定启用迁移的context,按理来说使用提示给出的指令即可完成制定context的迁移启用如下:
Enable-Migrations -ContextTypeName yourApplication.Models.Model1.
但是我在尝试中发现直接给出的复制指令会报出:
context type ‘yourApplication.Models.Model1.’ was not found in the assembly ‘oxhainanReeTest3’.
最终发现直接复制提示指令,句尾包含了一个句号。。。(气出猪叫)
删除句尾句号后,将context名作为Enable-Migrations的一个参数,加上双引号“”。
测试成功。
Enable-Migrations -ContextTypeName “yourApplication.Models.ApplicationDbContext”