Не создается , и не заполняется таблица __EFMigrationsHistory

325
26 сентября 2021, 12:10

Написал классы моделей, написал DBContext, попробовал сделать миграцию, вроде бы все получилось, однако, при выполнении миграции, или обновлении базы, происходит не понятное мне.

Используется MySQL как поставщик базы, и при выполнении миграции, не создается таблица:

Table 'mi_web_api.__efmigrationshistory' doesn't exist

Соответственно отпадает возможность делать откаты.

Что происходит не так?

Полный вывод при попытке сделтаь миграцию:

dotnet ef database update
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 2.2.6-servicing-10079 initialized 'ApiContext' using provider 'MySql.Data.EntityFrameworkCore' with options: None
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'mi_web_api'
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (244ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CREATE TABLE `Genres` (
          `Id` int NOT NULL AUTO_INCREMENT,
          `Name` text NULL,
          PRIMARY KEY (`Id`)
      );
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (232ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CREATE TABLE `Studios` (
          `Id` int NOT NULL AUTO_INCREMENT,
          `Name` text NULL,
          `Logotype` text NULL,
          PRIMARY KEY (`Id`)
      );
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (275ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CREATE TABLE `Games` (
          `Id` int NOT NULL AUTO_INCREMENT,
          `Name` varchar(767) NULL,
          `Year` int NOT NULL,
          `StudioId` int NULL,
          PRIMARY KEY (`Id`),
          CONSTRAINT `FK_Games_Studios_StudioId` FOREIGN KEY (`StudioId`) REFERENCES `Studios` (`Id`) ON DELETE RESTRICT
      );
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (343ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CREATE TABLE `GamesGenres` (
          `GameInfoId` int NOT NULL,
          `GenreInfoId` int NOT NULL,
          PRIMARY KEY (`GameInfoId`, `GenreInfoId`),
          CONSTRAINT `FK_GamesGenres_Games_GameInfoId` FOREIGN KEY (`GameInfoId`) REFERENCES `Games` (`Id`) ON DELETE CASCADE,
          CONSTRAINT `FK_GamesGenres_Genres_GenreInfoId` FOREIGN KEY (`GenreInfoId`) REFERENCES `Genres` (`Id`) ON DELETE CASCADE
      );
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (233ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CREATE INDEX `IX_Games_StudioId` ON `Games` (`StudioId`);
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (115ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CREATE INDEX `IX_Games_Id_Name` ON `Games` (`Id`, `Name`);
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (207ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CREATE INDEX `IX_GamesGenres_GenreInfoId` ON `GamesGenres` (`GenreInfoId`);
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT 1 FROM information_schema.tables
      WHERE table_name = '
      __EFMigrationsHistory' AND table_schema = DATABASE()
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT 1 FROM information_schema.tables
      WHERE table_name = '
      __EFMigrationsHistory' AND table_schema = DATABASE()
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT `MigrationId`, `ProductVersion`
      FROM `__EFMigrationsHistory`
      ORDER BY `MigrationId`;
MySql.Data.MySqlClient.MySqlException (0x80004005): Table 'mi_web_api.__efmigrationshistory' doesn't exist
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader()
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
Failed executing DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT `MigrationId`, `ProductVersion`
FROM `__EFMigrationsHistory`
ORDER BY `MigrationId`;
MySql.Data.MySqlClient.MySqlException (0x80004005): Table 'mi_web_api.__efmigrationshistory' doesn't exist
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader()
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.GetAppliedMigrations()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_1.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Table 'mi_web_api.__efmigrationshistory' doesn't exist
READ ALSO
объединение запросов БД

объединение запросов БД

Подскажите как объединить два запроса в один, в нете подходящей инфы не нашел

135
Проблема с list.add [дубликат]

Проблема с list.add [дубликат]

Недавно столкнулся с ошибкой "NullReferenceException: Object reference not set to an instance of an object" Можете помочь поправить, ума не приложу?

98
Сохранение списка экземпляров класса в базе данных

Сохранение списка экземпляров класса в базе данных

Есть класс, определяющий модель данных:

70