【发布时间】:2016-12-06 22:30:47
【问题描述】:
我正在使用 ASP.NET CORE 1.0.0 开发一个项目,并且我正在使用 EntityFrameworkCore。我有单独的程序集,我的项目结构如下所示:
ProjectSolution
-src
-1 Domain
-Project.Data
-2 Api
-Project.Api
在我的Project.Api 中是Startup 类
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ProjectDbContext>();
services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<ProjectDbContext>()
.AddDefaultTokenProviders();
}
DbContext 在我的Project.Data 项目中
public class ProjectDbContext : IdentityDbContext<IdentityUser>
{
public ProjectDbContext(DbContextOptions<ProjectDbContext> options) : base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var builder = new ConfigurationBuilder();
builder.SetBasePath(Directory.GetCurrentDirectory());
builder.AddJsonFile("appsettings.json");
IConfiguration Configuration = builder.Build();
optionsBuilder.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection"));
base.OnConfiguring(optionsBuilder);
}
}
当我尝试进行初始迁移时,我收到此错误:
“您的目标项目“Project.Api”与您的迁移程序集“Project.Data”不匹配。请更改您的目标项目或更改您的迁移程序集。 使用 DbContextOptionsBuilder 更改您的迁移程序集。例如。 options.UseSqlServer(connection, b => b.MigrationsAssembly("Project.Api"))。默认情况下,迁移程序集是包含 DbContext 的程序集。 通过使用包管理器控制台的默认项目下拉列表,或从包含迁移项目的目录中执行“dotnet ef”,将您的目标项目更改为迁移项目。”
看到这个错误后,我尝试执行位于Project.Api的这个命令:
dotnet ef --startup-project ../Project.Api --assembly "../../1 Data/Project.Data" 迁移添加 Initial
我得到了这个错误:
“选项“程序集”的意外值“../../1 Domain/Project.Data””
当我尝试使用“-assembly”参数执行命令时,我不知道为什么会出现此错误。
我无法从其他程序集创建初始迁移,我已经搜索了有关它的信息但没有得到任何结果。
有人遇到过类似的问题吗?
【问题讨论】:
-
是的,但我没有
t get fix the error, i tryed diferent options of commands with --startup-project and --assebly but i didnt 什么也得不到 -
不要使用 --assembly。这是一个应该从帮助消息中隐藏的内部实现细节,但由于github.com/aspnet/EntityFramework/issues/5188 无论如何都会显示出来
标签: c# asp.net-core entity-framework-core entity-framework-migrations