ALTER COLUMN migration with column type change requires USING [PostgreSQL]
Migration of type column type change generates script like:
ALTER TABLE "[table name]" ALTER COLUMN "[column name]" TYPE integer;
tha gets failed on the execution phase as it requires a hint:
ALTER TABLE "[table name]" ALTER COLUMN "[column name]" TYPE integer USING "[column name]"::integer;
EF Core version: 5.0.2 Database provider: Npgsql.EntityFrameworkCore.PostgreSQL Target framework: .NET 5.0 Operating system: IDE: Visual Studio 2019 16.10.4
Duplicate of https://github.com/npgsql/efcore.pg/issues/144
@aspirinv PostgreSQL will seamless perform column type alterations where the conversion is straightforward and non-destructive; for example, if you change an int property to a string, the generated ALTER COLUMN will work just fine. However, wherever the data conversion isn't straightforward or could fail, PostgreSQL requires the conversion SQL to be specified explicitly, and EF makes no attempt to hide that or do that for you. You're encouraged to edit the scaffolded migration and replace the failing AlterTable operation with raw SQL containing the exact conversion SQL you want.