Base solution for your next web application
Open Closed

Migration issue with PostgreSQL #11961


User avatar
0
pgummadapu created

Hello,

I am trying to run the migration process by following step by step instructions from:

https://aspnetboilerplate.com/Pages/Documents/EF-Core-PostgreSql-Integration

Beforehand I installed PostgreSQL server locally, tested it by accessing the database and created a simple test table with columns and data.

  1. I added all of the proper packages.
  2. Changed info in DbContext as per link
  3. Changed the connection strings as per article.
  4. Added "Configure DateTime Handling" by inserting inside DTSMigratorModule.cs I added AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); inside void PreInitialize() method.
  5. Added proper code to OnModelCreating method
  6. Removed all migration classes but left DbContextModelSnapshot (did not delete it) inside EntityFrameworkCore/Migrations folder.
  7. Opened Package Manager Console and selected the *.EntityFrameworkCore project.
  8. Ran "add-migration Initial_Migration" and this is what I am getting:

PM> add-migration Initial_Migration Build started... Build succeeded. The Entity Framework tools version '8.0.1' is older than that of the runtime '8.0.2'. Update the tools for the latest features and bug fixes. See https://aka.ms/AAc1fbw for more information. The property 'SubscriptionPayment.ExtraProperties' is a collection or enumeration type with a value converter but with no value comparer. Set a value comparer to ensure the collection/enumeration elements are compared correctly. The property 'SubscriptionPaymentProduct.ExtraProperties' is a collection or enumeration type with a value converter but with no value comparer. Set a value comparer to ensure the collection/enumeration elements are compared correctly. System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Initialize(ColumnOperation columnOperation, IColumn column, RelationalTypeMapping typeMapping, Boolean isNullable, IEnumerable1 migrationsAnnotations, Boolean inline) at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.InitializeColumnHelper(ColumnOperation columnOperation, IColumn column, Boolean inline) at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(IColumn source, IColumn target, DiffContext diffContext)+MoveNext() at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable1 sources, IEnumerable1 targets, DiffContext diffContext, Func4 diff, Func3 add, Func3 remove, Func4[] predicates)+MoveNext() at System.Linq.Enumerable.ConcatIterator1.MoveNext() at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(ITable source, ITable target, DiffContext diffContext)+MoveNext() at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable1 sources, IEnumerable1 targets, DiffContext diffContext, Func4 diff, Func3 add, Func3 remove, Func4[] predicates)+MoveNext() at System.Linq.Enumerable.ConcatIterator1.MoveNext() at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Sort(IEnumerable1 operations, DiffContext diffContext) at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDifferences(IRelationalModel source, IRelationalModel target) at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.

Any suggestions on what I am doing wrong or what I missed from the step by step url?

Thank you


1 Answer(s)
  • User Avatar
    0
    pgummadapu created

    Deleting DbContextModelSnapshot was the issue that caused null reference. I figured it out.