tortoise / aerich

A database migrations tool for TortoiseORM, ready to production.
https://github.com/tortoise/aerich
Apache License 2.0
841 stars 95 forks source link

Type change error #135

Closed Olegt0rr closed 3 years ago

Olegt0rr commented 3 years ago

Can't change field type with aerich

Example

State 1

class User(Model):
    id = CharField(max_length=32)

State 2

class User(Model):
    id = BigIntField()

Run upgrade

tortoise.exceptions.OperationalError: column "id" cannot be cast automatically to type bigint
HINT:  You might need to specify "USING id::bigint".

How to fix

Bad line (from migration)

ALTER TABLE "users" ALTER COLUMN "id" TYPE BIGINT;

Good line

ALTER TABLE "users" ALTER COLUMN "id" TYPE BIGINT USING id::bigint;
long2ice commented 3 years ago

Fixed, thanks!