efcore.pg icon indicating copy to clipboard operation
efcore.pg copied to clipboard

Migration fails with HasPostgresExtension.

Open sirentek opened this issue 10 years ago • 3 comments

Hi,

I decided to use Guid as primary key. Added these lines to my db context OnModelCreating:

            builder.HasPostgresExtension("uuid-ossp");

            builder.Entity<ApplicationUser>(b =>
            {
                b.Property(u => u.Id).HasDefaultValueSql("newid()");
            });

            builder.Entity<Role>(b =>
            {
                b.Property(u => u.Id).HasDefaultValueSql("newid()");
            });

SELECT UUID_GENERATE_V4() => tested and it worked via efcore 7 successfully.

Dropped my database via ef command utility. Deleted my migration folder content in solution.

When running dotnet ef migrations add Initial, I get this exception:

System.InvalidOperationException: The current CSharpMigrationOperationGenerator cannot scaffold operations of type 'Microsoft.EntityFrameworkCore.Migrations.Ope
rations.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, IndentedStringB
uilder 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 st
artupProject, 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.NpgsqlCreatePostgresExtens
ionOperation'. Configure your services to use one that can.

I use efcore rc2 version and my nuget feedback:

    <add key="AspNetRelease" value="https://www.myget.org/F/aspnetrelease/api/v3/index.json" />
    <add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
    <add key="Npgsql" value="https://www.myget.org/F/npgsql-unstable/" />

Is there anybody else having same issue ?

sirentek avatar Jun 06 '16 08:06 sirentek

Can you please include the exact version of the Npgsql EFCore provider you're using?

roji avatar Jun 06 '16 09:06 roji

1.Test: Cleaned my .nuget packages folder and restored when my project.json has these

    "Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.0-*",
    "Npgsql.EntityFrameworkCore.PostgreSQL.Design": "1.0.0-*",

Got the same error.

2.Test: I cleaned my .nuget packages folder and restored when project.json has these:

    "Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.0-rc2-release1",
    "Npgsql.EntityFrameworkCore.PostgreSQL.Design": "1.0.0-rc2-release1",

The error has gone :+1:

sirentek avatar Jun 06 '16 10:06 sirentek

I am closing this. Thank you!

sirentek avatar Jun 06 '16 10:06 sirentek