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

Migration tries to set callable object repr as column default in SQL, fails #147

Closed artem30801 closed 3 years ago

artem30801 commented 3 years ago

I made a custom object with call method and pass it like:

role_number = NextNumber()

class Role(Model):
    id = fields.IntField(pk=True)
    number = fields.IntField(default=role_number)

When I called "aerich migrate" it gives following error: AttributeError: 'NextNumber' object has no attribute 'name'

When I impelemnt name attribute for the object, it generates following SQL code in file in /migrate folder (among other lines) ALTER TABLE role MODIFY COLUMN number INT NOT NULL COMMENT 'Priority (ordering) of the role' DEFAULT '<function cogs.db_utils.NextNumber:<class \'cogs.roles.Role\'>:number>'; Obviously this leads to faililure of executing aerich upgrade command

long2ice commented 3 years ago

Yes, which should be ignore

long2ice commented 3 years ago

Fixed

artem30801 commented 3 years ago

Thank you!