Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

[Bug] migration da aula...

Logo abaixo, esta o resultado do meu update database, com erro..

PM> update-database
Build started...
Build succeeded.
... 
/// codigos SQL sem erros
...
Failed executing DbCommand (5ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CALL POMELO_BEFORE_DROP_PRIMARY_KEY(NULL, 'Sessoes');
ALTER TABLE `Sessoes` DROP PRIMARY KEY;
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (5ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CALL POMELO_BEFORE_DROP_PRIMARY_KEY(NULL, 'Sessoes');
      ALTER TABLE `Sessoes` DROP PRIMARY KEY;
MySqlConnector.MySqlException (0x80004005): Can't DROP 'PRIMARY'; check that column/key exists
   at MySqlConnector.Core.ServerSession.ReceiveReplyAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ServerSession.cs:line 894
   at MySqlConnector.Core.ResultSet.ReadResultSetHeaderAsync(IOBehavior ioBehavior) in /_/src/MySqlConnector/Core/ResultSet.cs:line 37
   at MySqlConnector.MySqlDataReader.ActivateResultSet(CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlDataReader.cs:line 130
   at MySqlConnector.MySqlDataReader.InitAsync(CommandListPosition commandListPosition, ICommandPayloadCreator payloadCreator, IDictionary`2 cachedProcedures, IMySqlCommand command, CommandBehavior behavior, Activity activity, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlDataReader.cs:line 483
   at MySqlConnector.Core.CommandExecutor.ExecuteReaderAsync(CommandListPosition commandListPosition, ICommandPayloadCreator payloadCreator, CommandBehavior behavior, Activity activity, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/CommandExecutor.cs:line 56
   at MySqlConnector.MySqlCommand.ExecuteNonQueryAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlCommand.cs:line 309
   at MySqlConnector.MySqlCommand.ExecuteNonQuery() in /_/src/MySqlConnector/MySqlCommand.cs:line 108
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
   at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Can't DROP 'PRIMARY'; check that column/key exists
PM> 

Pelo que entendi do erro: É um conflito em remover o sessao.id, mas o sessao.id não existe mais pois o BD foi dropado, e recriado com uma nova migration, mas gera esse erro... pois existe um migration com o primary key do sessao, e pelo que entendi ele esta tentando remover o sessao.id,

Assim dropei o banco e removi todas as minhas migrations, e criei uma nova... e funcionou...

1 resposta
solução!

Oi Marcelo, tudo bem?

O erro "Can't DROP 'PRIMARY'; check that column/key exists" indica exatamente o que você identificou, o comando SQL está tentando remover uma chave primária que não existe mais, provavelmente devido a mudanças nas migrações ou no banco de dados.

Fico feliz que você tenha conseguido resolver esse problema e que tenha compartilhado a solução que você usou, assim poderá ajudar outros alunos que estiverem enfrentando a mesma situação.

Caso surjam quaisquer dúvidas eu estarei à sua disposição.

Abraços e bons estudos!