Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Commented Unassigned: Customized migration history doesn't work well with initializer [1058]

$
0
0
Repro:
Create basic application with the model shown below
PM> Install-package entityframework -pre -version 20410
PM> Enable-Migrations
Add custom factory to migrations configuration file as shown below the model
Run the application
Note: EntityException is thrown with the message: "The underlying provider failed on Open."

This message should either be updated to be more informative or this issue should be rectified and the migrations table created in the initializer.

Model:
public class EntityContext : DbContext
{
public DbSet<Entity> Entities { get; set; }
}

public class Entity
{
public int ID { get; set; }
public string Title { get; set; }
public DateTime Timestamp { get; set; }
}

public class MyHistoryContext : HistoryContext
{
public MyHistoryContext(DbConnection existingConnection, bool contextOwnsConnection, string defaultSchema)
: base(existingConnection, contextOwnsConnection, defaultSchema)
{
}

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<HistoryRow>().ToTable("YourHistory.Table", "schema");
modelBuilder.Entity<HistoryRow>().Property(h => h.MigrationId).HasColumnName("migration_id");
modelBuilder.Entity<HistoryRow>().Property(h => h.ContextKey).HasColumnName("context_key");
modelBuilder.Entity<HistoryRow>().Property(h => h.Model).HasColumnName("metadata");
}
}

Configuration:
public Configuration()
{
AutomaticMigrationsEnabled = false;
HistoryContextFactory = (connection, ownsConnection, schema) =>
new MyHistoryContext(connection, ownsConnection, schema);
}
Comments: This is by design, we recently took a change to prevent database initializers creating the database if you have swapped to using Migrations. This prevents getting into a state where you have created a database using initializers that then won't work with your migrations because your first few migrations will conflict with what the initializer did.

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>