tortoise / aerich

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

Some columns missing from database table #161

Open FIRDOUS-BHAT opened 3 years ago

FIRDOUS-BHAT commented 3 years ago

There is an issue with the aerich migration that I observed is while executing aerich migrate all columns of a table do reflect in migration file but after executing aerich upgrade one or the other misses from database table.

Note: This issue arises sometimes only.

long2ice commented 3 years ago

Need more info

FIRDOUS-BHAT commented 3 years ago

Here is an example model,

class Course(Model): """ This references course of each competative exams """ id = fields.UUIDField(pk=True) name = fields.CharField(max_length=100, unique=True) slug = fields.CharField(max_length=250, unique=True) icon_image = fields.TextField() web_icon = fields.TextField(null=True, blank=True) is_active = fields.BooleanField(default=True) updated_at = fields.DatetimeField(null=True, blank=True) created_at = fields.DatetimeField(auto_now_add=True) preference = fields.ForeignKeyField( "models.Preference", related_name="courses", on_delete='CASCADE', )

While executing `aerich migrate`, it will have all the columns into the sql file but on executing `aerich migrate` it sometimes doesn't migrate some of the columns into the database. 

I'm using postgres database.
FIRDOUS-BHAT commented 3 years ago

@long2ice this issue still presists. Mentioning here one of the examples that I faced,

-- upgrade -- CREATE TABLE IF NOT EXISTS "bookmarkedvideos" ( "id" UUID NOT NULL PRIMARY KEY, "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, "student_id" UUID NOT NULL REFERENCES "student" ("id") ON DELETE CASCADE, "video_id" UUID NOT NULL REFERENCES "coursecategorylectures" ("id") ON DELETE CASCADE ); -- downgrade -- DROP TABLE IF EXISTS "bookmarkedvideos"; After aerich upgrade, I ran the create query but got this error,

tortoise.exceptions.OperationalError: column "created_at" of relation "bookmarkedvideos" does not exist