Skip to content
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

AuditLog table migration fail while seeding data on MySql (MariaDB 10.5) #678

Closed
drsmile1001 opened this issue Aug 13, 2020 · 2 comments
Closed
Assignees

Comments

@drsmile1001
Copy link

Describe the bug

Can't use Skoruba.IdentityServer4.Admin to seed data on empty database. It has migration fail.

To Reproduce

  • Host a empty MariaDB 10.5 on localhost.
  • Editing src\Skoruba.IdentityServer4.Admin\appsettings.json
    • ConnectionStrings replace by server=localhost;database=IdentityServer4Admin;user=root;password=123456;treattinyasboolean=true
    • DatabaseProviderConfiguration.ProviderType replace by MySql
  • Use VisualStudio run Skoruba.IdentityServer4.Admin
  • Migration fail happend

Relevant parts of the log file

info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 3.1.6 initialized 'IdentityServerConfigurationDbContext' using provider 'Pomelo.EntityFrameworkCore.MySql' with options: MigrationsAssembly=Skoruba.IdentityServer4.Admin.EntityFramework.MySql
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 3.1.6 initialized 'IdentityServerPersistedGrantDbContext' using provider 'Pomelo.EntityFrameworkCore.MySql' with options: MigrationsAssembly=Skoruba.IdentityServer4.Admin.EntityFramework.MySql
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 3.1.6 initialized 'AdminIdentityDbContext' using provider 'Pomelo.EntityFrameworkCore.MySql' with options: MigrationsAssembly=Skoruba.IdentityServer4.Admin.EntityFramework.MySql
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 3.1.6 initialized 'AdminLogDbContext' using provider 'Pomelo.EntityFrameworkCore.MySql' with options: MigrationsAssembly=Skoruba.IdentityServer4.Admin.EntityFramework.MySql
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 3.1.6 initialized 'AdminAuditLogDbContext' using provider 'Pomelo.EntityFrameworkCore.MySql' with options: MigrationsAssembly=Skoruba.IdentityServer4.Admin.EntityFramework.MySql
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 3.1.6 initialized 'IdentityServerDataProtectionDbContext' using provider 'Pomelo.EntityFrameworkCore.MySql' with options: MigrationsAssembly=Skoruba.IdentityServer4.Admin.EntityFramework.MySql
[18:06:28 ERR] Failed executing DbCommand (5ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
ALTER TABLE `AuditLog` MODIFY COLUMN `Id` bigint NOT NULL AUTO_INCREMENT;
[18:06:28 FTL] Host terminated unexpectedly
MySql.Data.MySqlClient.MySqlException (0x80004005): Incorrect table definition; there can be only one auto column and it must be defined as a key
 ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Incorrect table definition; there can be only one auto column and it must be defined as a key
   at MySqlConnector.Core.ServerSession.ReceiveReplyAsyncAwaited(ValueTask`1 task) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 775
...

My workaround

I found it can be fix by editing
src\Skoruba.IdentityServer4.Admin.EntityFramework.MySql\Migrations\AuditLogging\20200419131142_ChangeAuditLogToLong.cs

...
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            //migrationBuilder.DropPrimaryKey("PK_AuditLog", "AuditLog"); <---comment this line

            migrationBuilder.AlterColumn<long>(
                name: "Id",
                table: "AuditLog",
                nullable: false,
                oldClrType: typeof(int),
                oldType: "int")
                .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn)
                .OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn);

            //migrationBuilder.AddPrimaryKey("PK_AuditLog", "AuditLog", "Id"); <---comment this line
        }
...
@moemura
Copy link

moemura commented Aug 13, 2020

I did the same workaround for MySQL 8.0.
It's look like bug in Pomelo for dropping primary key without drop autoincrement attribute.

@skoruba
Copy link
Owner

skoruba commented Aug 13, 2020

Hi guys, thanks for reporting this issue - could you please send your solution via a PR?
Thanks.

@skoruba skoruba mentioned this issue Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants