迁移是单独创建数据库而不是表

Migrations is creating DB alone but not tables

我正在使用 EF Core 2.2.6-servicing-10079。通过几次迁移,我正在尝试创建一个新的数据库。一旦我 运行 update-database 它创建空白数据库但不应用迁移因此没有创建 tables 除了迁移 table.

Migrations 文件夹有多个迁移。

应用程序数据库上下文:

  public class ApplicationDbContext : IdentityDbContext<ApplicationUser>, ILocalizationDbContext
{
    private readonly IServiceProvider _serviceProvider;

    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }        

    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options,
        IServiceProvider serviceProvider)
        : base(options)
    {
        _serviceProvider = serviceProvider;
    }

    public DbSet<...

DBSnapShot:

    [DbContext(typeof(ApplicationDbContext))]
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
{
    protected override void BuildModel(ModelBuilder modelBuilder)
    {
        modelBuilder
            .HasAnnotation("ProductVersion", "2.2.6-servicing-10079")
            .HasAnnotation("Relational:MaxIdentifierLength", 128)
            .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

        modelBuilder.Entity(...

输出:

PM> Update-Database Microsoft.EntityFrameworkCore.Model.Validation[10400] Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data, this mode should only be enabled during development. Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 2.2.6-servicing-10079 initialized 'ApplicationDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: SensitiveDataLoggingEnabled MigrationsAssembly=Infrastructure Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (22ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT OBJECT_ID(N'[__EFMigrationsHistory]'); Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT OBJECT_ID(N'[__EFMigrationsHistory]'); Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (4ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT [MigrationId], [ProductVersion] FROM [__EFMigrationsHistory] ORDER BY [MigrationId]; Microsoft.EntityFrameworkCore.Migrations[20405] No migrations were applied. The database is already up to date. No migrations were applied. The database is already up to date. Done.

Shaun Wilson's answer on 解决了我的问题。

他的回答是这样的:

执行 "batch clean" 解决了我的问题,提示 EF 正在使用当前所选 'solution configuration (e.g. DEBUG)' 以外的文件夹中的 old/invalid 程序集。

要进行批量清理:

  1. Select 主菜单 -> 构建
  2. Select 批量构建...
  3. 点击Select全部
  4. 点击清理

关闭对话框,重建并重新尝试迁移。