Incorrect migration handling of enums with schema
See original GitHub issueIn this PR MethodCallCodeFragment
’s constructor with MethodInfo
was used instead of overload with string name of method. Overload of NpgsqlModelBuilderExtensions.HasPostgresEnum
with 3 arguments was used, BUT for public schema only two arguments passed to MethodCallCodeFragment
constructor. It leads to exception in migrations in RC1
. I think it’s kind of silly bug where two different MethodInfo
objects must be used.
Error from log:
System.ArgumentException: 'HasPostgresEnum' was invoked with 3 arguments, but has 2 parameters. (Parameter 'arguments')
at Microsoft.EntityFrameworkCore.Design.MethodCallCodeFragment..ctor(MethodInfo methodInfo, Object[] arguments) in Microsoft.EntityFrameworkCore.dll:token 0x6002169+0x5c
at Npgsql.EntityFrameworkCore.PostgreSQL.Design.Internal.NpgsqlAnnotationCodeGenerator.GenerateFluentApi(IModel model, IAnnotation annotation) in Npgsql.EntityFrameworkCore.PostgreSQL.dll:token 0x60006c1+0xbe
at Microsoft.EntityFrameworkCore.Design.AnnotationCodeGenerator.GenerateFluentApiCallsHelper[TAnnotatable,TCodeFragment](TAnnotatable annotatable, IDictionary`2 annotations, Func`3 generateCodeFragment)+MoveNext() in Microsoft.EntityFrameworkCore.Relational.dll:t
oken 0x6001816+0x61
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection) in System.Private.CoreLib.dll:token 0x6006dad+0xea
at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection) in System.Private.CoreLib.dll:token 0x6006d89+0x0
at Microsoft.EntityFrameworkCore.Design.AnnotationCodeGenerator.GenerateFluentApiCalls(IModel model, IDictionary`2 annotations) in Microsoft.EntityFrameworkCore.Relational.dll:token 0x60017fc+0x39
at Npgsql.EntityFrameworkCore.PostgreSQL.Design.Internal.NpgsqlAnnotationCodeGenerator.GenerateFluentApiCalls(IModel model, IDictionary`2 annotations) in Npgsql.EntityFrameworkCore.PostgreSQL.dll:token 0x60006c0+0x0
at Microsoft.EntityFrameworkCore.Design.IAnnotationCodeGenerator.GenerateFluentApiCalls(IAnnotatable annotatable, IDictionary`2 annotations) in Microsoft.EntityFrameworkCore.Relational.dll:token 0x600183d+0x5a
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateAnnotations(String builderName, IAnnotatable annotatable, IndentedStringBuilder stringBuilder, Dictionary`2 annotations, Boolean inChainedCall, Boolean leadingNewline) in Microsoft
.EntityFrameworkCore.Design.dll:token 0x6000343+0x0
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.Generate(String modelBuilderName, IModel model, IndentedStringBuilder stringBuilder) in Microsoft.EntityFrameworkCore.Design.dll:token 0x6000321+0x9e
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateMetadata(String migrationNamespace, Type contextType, String migrationName, String migrationId, IModel targetModel) in Microsoft.EntityFrameworkCore.Design.dll:token 0x600030b+0x
223
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language) in Microsoft.EntityFrameworkCore.Design.dll:token 0x6000397+0x2b3
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace) in Microsoft.EntityFrameworkCore.Design.dll:token 0x6000480+0xa5
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace) in Microsoft.EntityFrameworkCore.Design.dll:token 0x60003ee+0xc
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0() in Microsoft.EntityFrameworkCore.Design.dll:token 0x60006f8+0x0
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0() in Microsoft.EntityFrameworkCore.Design.dll:token 0x600070c+0x0
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) in Microsoft.EntityFrameworkCore.Design.dll:token 0x6000683+0xc
'HasPostgresEnum' was invoked with 3 arguments, but has 2 parameters. (Parameter 'arguments')
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
EF Core migration creates incorrect enums
So, migration, migration designer and model snapshot had another enums for some reason: Migration: migrationBuilder.AlterDatabase() .Annotation( ...
Read more >Safety Considerations When Using Enums in Avro Schemas
Extending enums breaks forwards compatibility. What this means in practice is that your consumers will not be able to consume any events ...
Read more >db:migrate modifies enum types in schema.rb provoking ...
Stack. Ruby 3.0.0, Rails 6.1.3, Postgres 14, macOS 12.2.1. Problem. When running db:migrate in my project, any enum in schema.rb
Read more >How to use Enums when using Entity Framework Core with ...
Our first option was to model the enum as a separate table and use an unmapped property to cast it to an enum,...
Read more >Why would you store an enum in DB?
So, I could be storing 'C' , 'H' , 'M' , and 'L' in the database. Or 'HIGH' and so on. This has...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, no problem.
Thanks @kislovs!