Skip to content

Upgrade from .NET6 to .NET8 throws exception during migration #1934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Soundman32 opened this issue Jul 23, 2024 · 1 comment
Open

Upgrade from .NET6 to .NET8 throws exception during migration #1934

Soundman32 opened this issue Jul 23, 2024 · 1 comment

Comments

@Soundman32
Copy link

Same issue as this #1823

Looking at the other issue, it was related to guid, which my migration doesn't contain. There are previous migrations that work correctly, but it always fails on this one.

Steps to reproduce

Upgraded from .NET6 to .NET8. Everything is latest.

Pomelo.EntityFrameworkCore.MySql 8.0.2
Microsoft.EntityFrameworkCore 8.0.7

Migration up method:

        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "granular_average",
                columns: table => new
                {
                    granularAverageId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    activityId = table.Column<int>(type: "int", nullable: false),
                    activityMetricId = table.Column<int>(type: "int", nullable: false),
                    concurrencyToken = table.Column<DateTime>(type: "timestamp(6)", rowVersion: true, nullable: true),
                    count = table.Column<int>(type: "int", nullable: false, defaultValue: 0),
                    countryCode = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    gender = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    name = table.Column<string>(type: "varchar(255)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    scale = table.Column<int>(type: "int", nullable: false),
                    total = table.Column<string>(type: "longtext", nullable: false, defaultValue: "AA==")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    yearsExperience = table.Column<int>(type: "int", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk-granular_average", x => x.granularAverageId);
                    table.ForeignKey(
                        name: "fk-granular_average-activity",
                        column: x => x.activityId,
                        principalTable: "activity",
                        principalColumn: "activityId",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "fk-granular_average-activityMetric",
                        column: x => x.activityMetricId,
                        principalTable: "activity_metric",
                        principalColumn: "activityMetricId",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "ix-granular_average-activityId",
                table: "granular_average",
                column: "activityId");

            migrationBuilder.CreateIndex(
                name: "ix-granular_average-activityMetricId",
                table: "granular_average",
                column: "activityMetricId");

            migrationBuilder.CreateIndex(
                name: "ix-granular_average-name",
                table: "granular_average",
                column: "name",
                unique: true);
        }

The issue

Exception thrown: 'System.NullReferenceException' in Microsoft.EntityFrameworkCore.Relational.dll

  Error Message:
   System.NullReferenceException : Object reference not set to an instance of an object.
  Stack Trace:
     at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindCollectionMapping(RelationalTypeMappingInfo info, Type modelType, Type providerType, CoreTypeMapping elementMapping)
   at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.<>c.<FindMappingWithConversion>b__8_0(ValueTuple`4 k, RelationalTypeMappingSource self)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd[TArg](TKey key, Func`3 valueFactory, TArg factoryArgument)
   at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMappingWithConversion(RelationalTypeMappingInfo mappingInfo, Type providerClrType, ValueConverter customConverter)
   at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMappingWithConversion(RelationalTypeMappingInfo mappingInfo, IReadOnlyList`1 principals)
   at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMapping(IProperty property)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.Property.<>c.<get_TypeMapping>b__94_0(IProperty property)
   at Microsoft.EntityFrameworkCore.Internal.NonCapturingLazyInitializer.EnsureInitialized[TParam,TValue](TValue& target, TParam param, Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.Property.get_TypeMapping()
   at Microsoft.EntityFrameworkCore.Metadata.Internal.Property.Microsoft.EntityFrameworkCore.Metadata.IReadOnlyProperty.FindTypeMapping()
   at Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.FindRelationalTypeMapping(IReadOnlyProperty property)
   at Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.GetColumnType(IReadOnlyProperty property)
   at Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.GetColumnType(IProperty property)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.CreateDefaultColumnMapping(ITypeBase typeBase, ITypeBase mappedType, TableBase defaultTable, TableMappingBase`1 tableMapping, Boolean isTph, Boolean isTpc)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.AddDefaultMappings(RelationalModel databaseModel, IEntityType entityType, IRelationalTypeMappingSource relationalTypeMappingSource)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Create(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, IRelationalTypeMappingSource relationalTypeMappingSource, Boolean designTime)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Add(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, IRelationalTypeMappingSource relationalTypeMappingSource, Boolean designTime)
   at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelRuntimeInitializer.InitializeModel(IModel model, Boolean designTime, Boolean prevalidation)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelRuntimeInitializer.Initialize(IModel model, Boolean designTime, IDiagnosticsLogger`1 validationLogger)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.FinalizeModel(IModel model)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateUpSql(Migration migration, MigrationsSqlGenerationOptions options)
   at Pomelo.EntityFrameworkCore.MySql.Migrations.Internal.MySqlMigrator.GenerateUpSql(Migration migration, MigrationsSqlGenerationOptions options)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.<>c__DisplayClass16_2.<GetMigrationCommandLists>b__2()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)

Further technical details

MySQL version: 8.2.0
Operating system: Windows
Pomelo.EntityFrameworkCore.MySql version: 8.0.2
Microsoft.AspNetCore.App version: 8.0

@Soundman32
Copy link
Author

Ha ha, I've been Googling this error for the last couple of days, and I'd forgotten I'd posted this. It's still an issue, even when using the latest .Net8 nugets (8.0.10). I wonder if it's a problem with Pomelo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant