peewee_migrate icon indicating copy to clipboard operation
peewee_migrate copied to clipboard

`--auto` creates invalid Python file

Open dev-zero opened this issue 9 years ago • 2 comments

I tried to use the --auto option to generate the migration files. The result is:

def migrate(migrator, database, fake=False, **kwargs):
    """Write your migrations here."""

    @migrator.create_model
    class BaseModel(pw.Model):

    @migrator.create_model
    class BasissetFamily(pw.Model):
        name = pw.CharField(max_length=255, unique=True)

    @migrator.create_model
    class MyModel1(pw.Model):
        family = pw.ForeignKeyField(db_column='family_id', rel_model=MyModel1, to_field='id')
        element = pw.CharField(max_length=255)
        basis = pw.TextField()

    @migrator.create_model
    class Model(pw.Model):

    @migrator.create_model
    class MyModel2(pw.Model):
        name = pw.CharField(max_length=255, unique=True)

The problem are the empty bodies for the BaseModel and Model classes which is invalid Python.

dev-zero avatar Jul 07 '16 11:07 dev-zero

the same goes for the rollback which contains the following invalid lines:

    migrator.remove_model('model')

    migrator.remove_model('basemodel')

dev-zero avatar Jul 07 '16 14:07 dev-zero

Your models just seem to be empty... you can ignore models by writing IGNORE=['basemodel'] in a conf.py in your migration directory.

rollback is completely valid python, but the models/tables might not be in the database because they are empty or so

Thorbijoern avatar Apr 20 '18 10:04 Thorbijoern