EF Core `update-database` on MySql fails with `__EFMigrationsHistory' doesn't exist`

前端 未结 1 1524
深忆病人
深忆病人 2021-01-03 10:42

I Create new project in .net core 1.1 with individual user account identity. I Add MySql Provider in Startup.cs:

servi         


        
相关标签:
1条回答
  • 2021-01-03 10:45

    This isn't related to ASP.NET Identity or ASP.NET Core. This is related to Entity Framework in general. When you update a database, EF uses the __EFMigrationsHistory to record which migrations were executed so it doesn't perform them again in the future.

    This functionality is implemented by the database provider, not EF itself. There was at least one case where the Npgsql provider for PostgresSQL didn't create the table.

    The solution is easy - create the table yourself :

    CREATE TABLE `__EFMigrationsHistory` 
    ( 
        `MigrationId` nvarchar(150) NOT NULL, 
        `ProductVersion` nvarchar(32) NOT NULL, 
         PRIMARY KEY (`MigrationId`) 
    );
    

    UPDATE

    There was another similar question in 2016. This is a bug of the official MySQL provider. The fix is to create the table. Not the only one either. Asynchronous operations are faked by running them on a different thread for example.

    I'd suggest you investigate third-party MySQL providers like Pomelo.EntityFrameworkCore.MySql. They found and fixed the migration history bug 1 year ago.

    Given that the owner of MySQL is Oracle, don't expect a lot of progress on the connector. Or the database.

    0 讨论(0)
提交回复
热议问题