DEV Community

Discussion on: Adding PostgreSQL support to your ASP.Net Core application via Docker

Collapse
 
aristotelesbr profile image
Aristóteles Coutinho • Edited

After exec dotnet ef database update command returns this error for me:

uild started...
Build succeeded.
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (76ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      ALTER TABLE "AspNetUsers" ALTER COLUMN "TwoFactorEnabled" TYPE boolean;
      ALTER TABLE "AspNetUsers" ALTER COLUMN "TwoFactorEnabled" SET NOT NULL;
      ALTER TABLE "AspNetUsers" ALTER COLUMN "TwoFactorEnabled" DROP DEFAULT;
Failed executing DbCommand (76ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
ALTER TABLE "AspNetUsers" ALTER COLUMN "TwoFactorEnabled" TYPE boolean;
ALTER TABLE "AspNetUsers" ALTER COLUMN "TwoFactorEnabled" SET NOT NULL;
ALTER TABLE "AspNetUsers" ALTER COLUMN "TwoFactorEnabled" DROP DEFAULT;
Npgsql.PostgresException (0x80004005): 42804: column "TwoFactorEnabled" cannot be cast automatically to type boolean
   at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
   at Npgsql.NpgsqlDataReader.NextResult()
   at Npgsql.NpgsqlCommand.ExecuteReaderAsync(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery()
   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 contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
  Exception data:
    Severity: ERROR
    SqlState: 42804
    MessageText: column "TwoFactorEnabled" cannot be cast automatically to type boolean
    Hint: You might need to specify "USING "TwoFactorEnabled"::boolean".
    File: tablecmds.c
    Line: 10363
    Routine: ATPrepAlterColumnType
42804: column "TwoFactorEnabled" cannot be cast automatically to type boolean
Enter fullscreen mode Exit fullscreen mode
Collapse
 
nuculabs_dev profile image
Nucu Labs

That's strange, are you starting /w a fresh database? At the first look this seems to be an issue between ASP.NET Core and PostgreSql, try testing /w Maria/Mysql also.