Reputation: 733
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.
Upvotes: 2
Views: 1958
Reputation: 733
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:
Close dialog, rebuild and re-attempt migration.
Upvotes: 2