Base solution for your next web application
Open Closed

Migrator on Mac Core and MySQL #3061


User avatar
0
pkouame created

Hi I'm attempting to use the latest Migrator to create some new MySQL migrations on macOS Sierra. I have a plain vanilla (just downloaded yesterday) project core+angular2+netcore Mac project. Have all the necessary MySQL dependencies, connection string and DbContextConfigurer wired. Builds fine. But... I get the following when attempting a run after cleaning all of my EntityFramework migrations:

2017-04-27 15:08:59 | System.InvalidOperationException: The entity type 'EditionFeatureSetting' is part of a hierarchy, but does not have a discriminator property configured.
   at Microsoft.EntityFrameworkCore.Internal.ModelValidator.ShowError(String message)
   at Microsoft.EntityFrameworkCore.Internal.RelationalModelValidator.ValidateDiscriminator(IEntityType entityType)
   at Microsoft.EntityFrameworkCore.Internal.RelationalModelValidator.ValidateDiscriminatorValues(IEntityType rootEntityType)
   at Microsoft.EntityFrameworkCore.Internal.RelationalModelValidator.ValidateInheritanceMapping(IModel model)
   at Microsoft.EntityFrameworkCore.Internal.RelationalModelValidator.Validate(IModel model)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
   at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()

...fault from AbpZeroMigrator.CreateOrMigrate(AbpTenantBase tenant, Action seedAction)

Looks like its expecting someone to have a discriminator property defined.

Has anyone experienced this before? I haven't tried the out-of-the-box SqlServer provider. But I'm assuming it works. Maybe not on macOS :-(

Also, from my research the MySQL dataprovider may have some issues with this see [https://www.bountysource.com/issues/42692842-the-entity-type-is-part-of-a-hierarchy-but-with-no-discriminator-property-configured])

Lastly, what is the exact purpose of the ...ModelSnapshotClass in the Migrator project?

Regards, P


7 Answer(s)
  • User Avatar
    0
    pkouame created

    Here is the full log of the Migrator dotnet run

    EBUG 2017-04-27 15:08:51,727 [1    ] Abp.Modules.AbpModuleManager             - Loading Abp modules...
    DEBUG 2017-04-27 15:08:51,764 [1    ] Abp.Modules.AbpModuleManager             - Found 10 ABP modules in total.
    DEBUG 2017-04-27 15:08:52,120 [1    ] Abp.Modules.AbpModuleManager             - Loaded module: ZeroCoreAngularCore.Migrator.ZeroCoreAngularCoreMigratorModule, ZeroCoreAngularCore.Migrator, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null
    DEBUG 2017-04-27 15:08:52,124 [1    ] Abp.Modules.AbpModuleManager             - Loaded module: ZeroCoreAngularCore.EntityFrameworkCore.ZeroCoreAngularCoreEntityFrameworkCoreModule, ZeroCoreAngularCore.EntityFrameworkCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null
    DEBUG 2017-04-27 15:08:52,124 [1    ] Abp.Modules.AbpModuleManager             - Loaded module: Abp.Zero.EntityFrameworkCore.AbpZeroCoreEntityFrameworkCoreModule, Abp.ZeroCore.EntityFrameworkCore, Version=2.0.2.0, Culture=neutral, PublicKeyToken=null
    DEBUG 2017-04-27 15:08:52,124 [1    ] Abp.Modules.AbpModuleManager             - Loaded module: Abp.Zero.AbpZeroCoreModule, Abp.ZeroCore, Version=2.0.2.0, Culture=neutral, PublicKeyToken=null
    DEBUG 2017-04-27 15:08:52,125 [1    ] Abp.Modules.AbpModuleManager             - Loaded module: Abp.Zero.AbpZeroCommonModule, Abp.Zero.Common, Version=2.0.2.0, Culture=neutral, PublicKeyToken=null
    DEBUG 2017-04-27 15:08:52,125 [1    ] Abp.Modules.AbpModuleManager             - Loaded module: Abp.AbpKernelModule, Abp, Version=2.0.2.0, Culture=neutral, PublicKeyToken=null
    DEBUG 2017-04-27 15:08:52,128 [1    ] Abp.Modules.AbpModuleManager             - Loaded module: Abp.EntityFrameworkCore.AbpEntityFrameworkCoreModule, Abp.EntityFrameworkCore, Version=2.0.2.0, Culture=neutral, PublicKeyToken=null
    DEBUG 2017-04-27 15:08:52,128 [1    ] Abp.Modules.AbpModuleManager             - Loaded module: ZeroCoreAngularCore.ZeroCoreAngularCoreCoreModule, ZeroCoreAngularCore.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null
    DEBUG 2017-04-27 15:08:52,129 [1    ] Abp.Modules.AbpModuleManager             - Loaded module: Abp.AutoMapper.AbpAutoMapperModule, Abp.AutoMapper, Version=2.0.2.0, Culture=neutral, PublicKeyToken=null
    DEBUG 2017-04-27 15:08:52,129 [1    ] Abp.Modules.AbpModuleManager             - Loaded module: Abp.MailKit.AbpMailKitModule, Abp.MailKit, Version=2.0.2.0, Culture=neutral, PublicKeyToken=null
    DEBUG 2017-04-27 15:08:52,134 [1    ] Abp.Modules.AbpModuleManager             - 10 modules loaded.
    DEBUG 2017-04-27 15:08:52,496 [1    ] ameworkCore.AbpEntityFrameworkCoreModule - Registering DbContext: ZeroCoreAngularCore.EntityFrameworkCore.ZeroCoreAngularCoreDbContext, ZeroCoreAngularCore.EntityFrameworkCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null
    DEBUG 2017-04-27 15:08:52,985 [1    ] Abp.Localization.LocalizationManager     - Initializing 3 localization sources.
    DEBUG 2017-04-27 15:08:53,045 [1    ] Abp.Localization.LocalizationManager     - Initialized localization source: Abp
    DEBUG 2017-04-27 15:08:53,058 [1    ] Abp.Localization.LocalizationManager     - Initialized localization source: AbpZero
    DEBUG 2017-04-27 15:08:53,087 [1    ] Abp.Localization.LocalizationManager     - Initialized localization source: ZeroCoreAngularCore
    DEBUG 2017-04-27 15:08:53,161 [1    ] Abp.AutoMapper.AbpAutoMapperModule       - Found 1 classes define auto mapping attributes
    DEBUG 2017-04-27 15:08:53,161 [1    ] Abp.AutoMapper.AbpAutoMapperModule       - ZeroCoreAngularCore.Friendships.Cache.FriendCacheItem
    INFO  2017-04-27 15:08:54,633 [1    ] ZeroCoreAngularCore.Migrator.Log         - Host database: server=127.0.0.1;userid=root;pwd=Me;port=3306;database=ZeroCoreAngularCoreDb;sslmode=none;
    INFO  2017-04-27 15:08:54,633 [1    ] ZeroCoreAngularCore.Migrator.Log         - Continue to migration for this host database and all tenants..? (Y/N): 
    INFO  2017-04-27 15:08:58,704 [1    ] ZeroCoreAngularCore.Migrator.Log         - HOST database migration started...
    INFO  2017-04-27 15:08:59,782 [1    ] ZeroCoreAngularCore.Migrator.Log         - An error occured during migration of host database:
    INFO  2017-04-27 15:08:59,812 [1    ] ZeroCoreAngularCore.Migrator.Log         - System.InvalidOperationException: The entity type 'EditionFeatureSetting' is part of a hierarchy, but does not have a discriminator property configured.
       at Microsoft.EntityFrameworkCore.Internal.ModelValidator.ShowError(String message)
       at Microsoft.EntityFrameworkCore.Internal.RelationalModelValidator.ValidateDiscriminator(IEntityType entityType)
       at Microsoft.EntityFrameworkCore.Internal.RelationalModelValidator.ValidateDiscriminatorValues(IEntityType rootEntityType)
       at Microsoft.EntityFrameworkCore.Internal.RelationalModelValidator.ValidateInheritanceMapping(IModel model)
       at Microsoft.EntityFrameworkCore.Internal.RelationalModelValidator.Validate(IModel model)
       at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
       at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
       at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
       at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
       at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
       at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServiceCollectionExtensions.<>c.<AddEntityFramework>b__0_13(IServiceProvider p)
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
       at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
       at Microsoft.EntityFrameworkCore.Infrastructure.RelationalServiceCollectionExtensions.<>c.<AddRelational>b__0_8(IServiceProvider p)
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
       at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
       at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
       at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)
       at Abp.Zero.EntityFrameworkCore.AbpZeroDbMigrator`1.CreateOrMigrate(AbpTenantBase tenant, Action`1 seedAction)
       at ZeroCoreAngularCore.Migrator.MultiTenantMigrateExecuter.Run(Boolean skipConnVerification) in /Users/me/Dev/zero/ZeroCoreAngularCore/aspnet-core/src/ZeroCoreAngularCore.Migrator/MultiTenantMigrateExecuter.cs:line 62
    INFO  2017-04-27 15:08:59,812 [1    ] ZeroCoreAngularCore.Migrator.Log         - Canceled migrations.
    DEBUG 2017-04-27 15:09:02,009 [1    ] Abp.Modules.AbpModuleManager             - Shutting down has been started
    DEBUG 2017-04-27 15:09:02,009 [1    ] Abp.Modules.AbpModuleManager             - Shutting down completed.
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    We didn't test latest version with MySql. Did you deleted all migration files and created migrations for MySql database after changing connection string, right ? Because current migration is created for SqlServer.

  • User Avatar
    0
    pkouame created

    Of course.

    Setting the Migrator aside for the moment, I got a full MySQL migration and database update working using cli dotnet with this stack only:

    <PackageReference Include="MySqlConnector" Version="*" />
    
        <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="1.1.1-*" />
        <PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.1-*" />
    

    I get a full set of MySQL migrations, design and snapshot that create the base db just fine. It looks like this stack is more lenient with TPH model configuration conventions. I tried many combinations including the latest from MySql, Sapient and others. But most are VERY sensitive to Abp's TPH inheritance model and choke on discriminators (something to do with EntityFrameworkCore's RelationalModelValidator). I believe the convention for EF core is to provide values for all non-abstract entities in the mapped hierarchy. Since Abp's base types are not abstract (meant to be instantiated - right? ), then hey must have a discriminator value provided. So I got around that with configuring them in dbContext's OnCreate explicitly:

    modelBuilder.Entity<FeatureSetting>(b =>
                {
                    b.HasDiscriminator<string>("Discriminator")
                        .HasValue<FeatureSetting>(nameof(FeatureSetting))
                        .HasValue<EditionFeatureSetting>(nameof(EditionFeatureSetting))
                        .HasValue<TenantFeatureSetting>(nameof(TenantFeatureSetting));
                });
    
                modelBuilder.Entity<PermissionSetting>(b =>
                {
                    b.HasDiscriminator<string>("Discriminator")
                        .HasValue<PermissionSetting>(nameof(PermissionSetting))
                        .HasValue<RolePermissionSetting>(nameof(RolePermissionSetting))
                        .HasValue<UserPermissionSetting>(nameof(UserPermissionSetting));
                });
    

    That's one issue. I want to try the other more conventional package stacks and dataproviders, but would like your opinion on the TPH model configuration and why it passes muster with SqlServer (haven't tested that myself yet on Mac). Also I run into netcoreapi 1.1 incompatibilities with some.

    But at least I've got a database and I'm on to Seeding now :-)

    Next up : I get a DbUpdateException when seeding tries to update a DisplayName column:

    System.Exception: A DbUpdateException was caught while saving changes.  ---> Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException: Incorrect string value: '\xD8\xA7\xD9\x84\xD8\xB9...' for column 'DisplayName' at row 1
    

    Could this be some sort of language or culture (pun intended :-) ) issue? I've overiden my DbContext's SaveChange() to capture a little more from the exception, but would be helpful if I could pinpoint more on the exact table and column its attempting to update. I am still on my Pomelo stack.

    Thanks in advance. Hope this additional testing helps those of you on macOS. It looks promising.

    P

  • User Avatar
    0
    pkouame created

    Yes, language/unicode support is slightly off somewhere for MySql. I think some MySql db configuration is required since it doesn't support unicode by default.

    In the meantime, and as a dirty shortcut, I converted all the unicode strings in GetInitialLanguages() with some brute force encoding to ascii. Not pretty for the moment, I know. But the seeding completes (albeit some weird characters in my non-english language table rows). But the API HOST is UP!

    After tweaking some host and client urls on both front and back end, the ANGULAR CLIENT is UP!

    NOTE: I had to change the ng server parameter to --live-reload-client [url] since the old style is not supported anymore.

    So , after some hair pulling, I confirm that this bleeding edge configuration:

    aspnet core + Angular2 + netcoreapi1.1

    • latest dotnetsdk
    • latest npm,
    • latest node(current not LTS)
    • latest ng
    • latest MySQL (see supported package stack below)

    solution is up on macOS Sierra 10.2.2!

    Plus all development on latest VS Code. Sweet. Much better experience than win10 vs2017 since I'm on a VM there. So much faster...

    Hope this helps someone.

    PS: would still like your opinion on some the issues I am discovering

    P

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thank you very much for your great work and feedback :) . We didn't have a chance to try AspNet Zero on MAC. We will take your work into consideration for next release.

  • User Avatar
    0
    pkouame created

    No problem man! I realize you need a much larger team to test all the combinations and platforms you support, so I'm more than happy to contribute as a subscriber and follower. Hopefully you can grow into that :D !

    Ultimately my goal is to sweeten our development options with a pure macOS .net development option and ms + your platform affords that now. I am finding that a VS Code (with tons of extensions) + DataGrid dev environment is turning out to be a bang up substitute to windoz (and some of our developers are running it in VM so doubly painful). Tons faster and overall much more enjoyable...

    MySql was just a temporary stop to build a local sandbox environment. Will be switching to sqlserver Azure for most of our work. But I hope this helps some out there.

    I have started to record some of my findings in github. Leave it up to you decide if and when to merge.

    Do you entertain push requests?

    Regards, P (<a href="mailto:[email protected]">[email protected]</a>)

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    We only work for pull requests at the moment, even some of our team members work in this way. We will be very happy if you send your works as pull request.

    Thanks again for your great effort on this :)