Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Programmatic Scaffold-Migration Issue After Updating to 9.0.0 #35146

@oONoobMasterOo

Description

@oONoobMasterOo

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"); 

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions