efcore.pg: Migration fails with HasPostgresExtension

possibly related to #46 and the 1.0.0 release. but

System.InvalidOperationException: The current CSharpMigrationOperationGenerator cannot scaffold operations of type 'Microsoft.EntityFrameworkCore.Migrations.Operations.NpgsqlCreatePostgresExtensionOperation'. Configure your services to use one that can.
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(MigrationOperation operation, IndentedStringBuilder builder)
   at CallSite.Target(Closure , CallSite , CSharpMigrationOperationGenerator , Object , IndentedStringBuilder )
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(String builderName, IReadOnlyList`1 operations, IndentedStringBuilder builder)
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateMigration(String migrationNamespace, String migrationName, IReadOnlyList`1 upOperations, IReadOnlyList`1 downOperations)
   at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace)
   at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.Execute(CommonOptions commonOptions, String name, String outputDir, String context, String environment, Action`1 reporter)
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
The current CSharpMigrationOperationGenerator cannot scaffold operations of type 'Microsoft.EntityFrameworkCore.Migrations.Operations.NpgsqlCreatePostgresExtensionOperation'. Configure your services to use one that can.

caused by:

        protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.HasPostgresExtension("uuid-ossp");

            base.OnModelCreating(builder);
        }

the author in #46 said they cleared up this issue by cleaning nuget packages and restoring again, but this has not helped.

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 46 (20 by maintainers)

Commits related to this issue

Most upvoted comments

I’ll look into this asap and release a 1.0.2 if necessary

I’ll release 1.0.1 in a day or two… hang in there

Is there any workaround for now? This is blocker for me. I need to use modelBuilder.HasPostgresExtension("uuid-ossp"); to generate migration, but when adding this it’s still failed with

The current CSharpMigrationOperationGenerator cannot scaffold operations of type 'Mic
rosoft.EntityFrameworkCore.Migrations.Operations.NpgsqlCreatePostgresExtensionOperati
on'. Configure your services to use one that can.

Not really… But will do my best to at least make CI packages available.

I just upgraded to 1.0.1 but i’m still getting this error:

System.InvalidOperationException: The current CSharpMigrationOperationGenerator cannot scaffold operations of type 'Microsoft.EntityFrameworkCore.Migrations.Operations.NpgsqlCreatePostgresExtensionOperation'. Configure your services to use one that can.    at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(MigrationOperation operation, IndentedStringBuilder builder)
   at CallSite.Target(Closure , CallSite , CSharpMigrationOperationGenerator , Object , IndentedStringBuilder )
    at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(String builderName, IReadOnlyList`1 operations, IndentedStringBuilder builder)
    at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateMigration(String migrationNamespace, String migrationName, IReadOnlyList`1 upOperations, IReadOnlyList`1 downOperations)
    at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace) 
   at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
    at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.Execute(CommonOptions commonOptions, String name, String outputDir, String context, String environment, Action`1 reporter) 
   at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.<>c__DisplayClass0_0.<Configure>b__0()
    at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) 
   at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
 The current CSharpMigrationOperationGenerator cannot scaffold operations of type 'Microsoft.EntityFrameworkCore.Migrations.Operations.NpgsqlCreatePostgresExtensionOperation'. Configure your services to use one that can.

This is happening executing command in package manager console:

add-migration 1_Initial

@allangomessl, 1.0.0-release-1 would be a prerelease, not a stable release which is what we want (read about semver and nuget versioning). I’ll try to get 1.0.1 out the door soon.

@roji Thanks. Adding Npgsql.EntityFrameworkCore.PostgreSQL.Design 1.0.1 to package.json file has fixed the issue, too.

Thanks @roji.

Was getting error even after upgrade to 1.0.1.

Got it fixed by adding Npgsql.EntityFrameworkCore.PostgreSQL.Design.

@bsheldrick, @ivankarpey, I can’t see the error happening…

I have a test project with a dependency on Npgsql.EFCore.PostgreSQL 1.0.0 that has builder.HasPostgresExtension("uuid-ossp") in the context. Doing dotnet ef migrations add initial fails as expected. Once I change the dependency to 1.0.1 (and do dotnet restore), running the same command succeeds…

Can you please double-check your project.json and make sure you ran dotnet restore? If you’re still getting the issue please try posting a link to a sample project which shows the issue.

As well upgraded to 1.0.1 and command

dotnet ef migrations add Initial throw exception, which is the same as for @bsheldrick

PM> dotnet ef migrations add Initial
Project Cnzr.Api (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
dotnet.exe : System.InvalidOperationException: The current CSharpMigrationOperationGenerator cannot scaffold operati
ons of type 'Microsoft.EntityFrameworkCore.Migrations.Operations.NpgsqlCreatePostgresExtensionOperation'. Configure 
your services to use one that can.At line:1 char:1
+ dotnet ef migrations add Initial
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (System.InvalidO...e one that can.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(MigrationOperation 
operation, IndentedStringBuilder builder)

   at CallSite.Target(Closure , CallSite , CSharpMigrationOperationGenerator , Object , IndentedStringBuilder )
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(String builderName,
 IReadOnlyList`1 operations, IndentedStringBuilder builder)
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateMigration(String migrationNa
mespace, String migrationName, IReadOnlyList`1 upOperations, IReadOnlyList`1 downOperations)
   at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, S
tring rootNamespace, String subNamespace)

   at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.AddMigration(String name, String outputDir, String c
ontextType)

   at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.Execute(CommonOptions commonOptions, String name,
 String outputDir, String context, String environment, Action`1 reporter)

   at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.<>c__DisplayClass0_0.<Configure>b__0()

   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)

   at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)

The current CSharpMigrationOperationGenerator cannot scaffold operations of type 'Microsoft.EntityFrameworkCore.Migr
ations.Operations.NpgsqlCreatePostgresExtensionOperation'. Configure your services to use one that can.