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

别来无恙 提交于 2019-12-01 11:18:23

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!