tortoise / aerich

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

Wrong `null=True` migration behaviour #142

Closed Olegt0rr closed 3 years ago

Olegt0rr commented 3 years ago

aerich didn't see adding null=True to the field

It seems fix for #135 added a new bug

How to reproduce

1. Create model and migrations

class Question(Model):
    text = TextField()

2. Set field as optional

class Question(Model):
    text = TextField(null=True)

3. Create migration

Result:

-- upgrade --
ALTER TABLE "question" ALTER COLUMN "text" TYPE TEXT USING "text"::TEXT;
-- downgrade --
ALTER TABLE "question" ALTER COLUMN "text" TYPE TEXT USING "text"::TEXT;

Expected result:

-- upgrade --
ALTER TABLE "question" ALTER COLUMN "text" DROP NOT NULL;
-- downgrade --
ALTER TABLE "question" ALTER COLUMN "text" SET NOT NULL;
long2ice commented 3 years ago

Fixed