Migrations is creating DB alone but not tables

c# ef-core-2.2 entity-framework-core

Question

I'm using EF Core 2.2.6-servicing-10079. With several migrations, I'm trying to create a new DB. Once I run update-database it creates the blank DB but doesn't apply migrations and hence no tables are created except the migration table.

Migrations folder has several migrations.

ApplicationDbContext :

  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(...

Output:

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.

1
0
8/16/2019 5:22:37 PM

Accepted Answer

Shaun Wilson's answer on https://stackoverflow.com/a/27895448/362261 has solved my problem.

His answer goes like this:

Doing a "batch clean" solved my problem, suggesting EF was using an old/invalid assembly from a folder other than the currently selected 'solution configuration (e.g. DEBUG)'.

To do a batch clean:

  1. Select Main Menu -> Build
  2. Select Batch Build...
  3. Click Select All
  4. Click Clean

Close dialog, rebuild and re-attempt migration.

0
8/17/2019 10:59:28 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow