-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Milestone
Description
After updating Npgsql to version 9.0.0, I encounter the following exception while attempting to scaffold migrations programmatically:
System.InvalidOperationException: Metadata changes are not allowed when the model has been marked as read-only.
at Microsoft.EntityFrameworkCore.Infrastructure.Annotatable.EnsureMutable()
at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.RemoveAnnotation(String name)
at Microsoft.EntityFrameworkCore.Infrastructure.Annotatable.Microsoft.EntityFrameworkCore.Metadata.IMutableAnnotatable.RemoveAnnotation(String name)
at Microsoft.EntityFrameworkCore.Migrations.Internal.SnapshotModelProcessor.Process(IReadOnlyModel model, Boolean resetVersion)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language, Boolean dryRun)
my scaffold code:
var services = new ServiceCollection().AddEntityFrameworkDesignTimeServices().AddDbContextDesignTimeServices(context);
var designTimeServices = new SqlServerDesignTimeServices();
designTimeServices.ConfigureDesignTimeServices(services);
var serviceProvider = services.BuildServiceProvider();
var scaffolder = serviceProvider.GetRequiredService<IMigrationsScaffolder>();
var migrationPath = Path.Combine(Hosting.ContentRootPath, @"..\", SystemName, "Migrations", DbContext.UseSqlServerProvider ? "SqlServer" : "NpgSql");
if (!Directory.Exists(migrationPath)) Directory.CreateDirectory(migrationPath);
var migration = scaffolder.ScaffoldMigration("my-migration-name","namespace");