klen / peewee_migrate

Simple migration engine for Peewee
MIT License
352 stars 86 forks source link

Bug report: Failed when reference a custom fields #209

Closed lovexuan closed 1 year ago

lovexuan commented 2 years ago

The model definition seems like:

class MySQLTimestampField(TimestampField):
    field_type = 'timestamp'

class Table1(Model):
    timestamp_field = MySQLTimestampField()

and the generated code seems like:

import peewee as pw

...
@migrator.create_model
class Table1(pw.Model):
    timestamp_field = pw.MySQLTimestampField()

When I execute router.run(), it raise AttributeError: module 'peewee' has no attribute 'MySQLTimestampField'.

The suggestion is, scan all the referenced fields first, and get module by class.__module__, then generate codes by this relation.

klen commented 1 year ago

should be fixed in the latest versions