{"id":726,"date":"2020-05-30T08:11:31","date_gmt":"2020-05-30T08:11:31","guid":{"rendered":"https:\/\/bruceng.com\/dev\/?p=726"},"modified":"2020-05-30T08:11:31","modified_gmt":"2020-05-30T08:11:31","slug":"ef-core-update-database-failed-with-mysql","status":"publish","type":"post","link":"https:\/\/bruceng.com\/dev\/?p=726","title":{"rendered":"EF Core Update-Database failed with MySQL"},"content":{"rendered":"\n<p>When trying to use the code first approach of Entity Framework Core to generate database and tables using MySQL. When running Update-Database in the package console manager, it shows an error saying table __efmigrationhistory doesn&#8217;t exists.<\/p>\n\n\n\n<p>After digging in Stackoverflow, it seems that it&#8217;s a bug with the official MySQL connector. And at the time of this writing with this version 8.0.20 and .NET Core 3.1, this bug hasn&#8217;t been fixed. The connector is supposed to create this table for migration.<\/p>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/a\/46090571\/9191495\">https:\/\/stackoverflow.com\/a\/46090571\/9191495<\/a><\/p>\n\n\n\n<p>In order to solve this problem there are two solutions<\/p>\n\n\n\n<p>-Don&#8217;t use the official connector, use Pomelo.EntityFramework.MySql<\/p>\n\n\n\n<p><a href=\"https:\/\/www.nuget.org\/packages\/Pomelo.EntityFrameworkCore.MySql\">https:\/\/www.nuget.org\/packages\/Pomelo.EntityFrameworkCore.MySql<\/a><\/p>\n\n\n\n<p>-Alternatively create, the table yourself<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE `__EFMigrationsHistory` \n( \n    `MigrationId` nvarchar(150) NOT NULL, \n    `ProductVersion` nvarchar(32) NOT NULL, \n     PRIMARY KEY (`MigrationId`) \n);<\/code><\/pre>\n\n\n\n<p>It&#8217;s a waste of time, but what can one do.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When trying to use the code first approach of Entity Framework Core to generate database and tables using MySQL. When running Update-Database in the package console manager, it shows an error saying table __efmigrationhistory doesn&#8217;t exists. After digging in Stackoverflow, it seems that it&#8217;s a bug with the official MySQL connector. And at the time &hellip; <a href=\"https:\/\/bruceng.com\/dev\/?p=726\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;EF Core Update-Database failed with MySQL&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[98,105,106],"class_list":["post-726","post","type-post","status-publish","format-standard","hentry","category-problems","tag-asp-net-core","tag-entity-framework-core","tag-mysql"],"_links":{"self":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=726"}],"version-history":[{"count":1,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/726\/revisions"}],"predecessor-version":[{"id":727,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/726\/revisions\/727"}],"wp:attachment":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}