I did a ‘database first’ reverse engineering of an existing database to create a model for Entity Framework.
I then tried to use that model to create a migration and subsequent new database on a MariaDB instance running under Windows.
I kept getting an error message “Table ‘__efmigrationshistory’ already exists” whenever I ran “dotnet ef database update”. I suspected the issue was to do with case sensitivity of the table name(s).
Things I tried to resolve the issue:
- Manually rename the table in the database to lower case.
- Change the lower_case_table_names setting to 2 in my.ini (location is set in the windows service settings. Service must be restarted to take effect)
- Change the table name in the Context.cs file
None of which worked.
Turned out the error was because I had scaffolded the database from the existing database which already had the EFMigrationsHistory table in it, so Entity Framework created a class in the scaffolded model for that table.
I deleted that entity, removed the migration and deleted the database. Then recreated the migration and updated the database and all was fine.