klen / peewee_migrate

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

`--auto` does not know fields from the Peewee Playhouse #17

Open dev-zero opened 8 years ago

dev-zero commented 8 years ago

We are using the BinaryJSONField from the Playhouse module for PostgreSQL (see http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#postgres-ext).

The migrations file contains then the following:

    @migrator.create_model
    class Result(pw.Model):
        energy = pw.DoubleField()
        task = pw.ForeignKeyField(db_column='task_id', rel_model=Task, to_field='id')
        filename = pw.CharField(max_length=255, null=True)
        data = pw.BinaryJSONField(index=True, null=True)

while it should maybe be something like:

import playhouse.postgres_ext as pw_pext

[...]

    @migrator.create_model
    class Result(pw.Model):
        energy = pw.DoubleField()
        task = pw.ForeignKeyField(db_column='task_id', rel_model=Task, to_field='id')
        filename = pw.CharField(max_length=255, null=True)
        data = pw_pext.BinaryJSONField(index=True, null=True)

In the original models file I have:

from playhouse.postgres_ext import BinaryJSONField
zet4 commented 8 years ago

Same happens for me when using muffin_peewee. I have from muffin_peewee import JSONField in models yet migration too ends up having pw.JSONField.

It's not hard to manually change the migration but it would be awesome if it would automatically recognize to what a field belongs to. (maybe using inspect? I don't know specific inner workings of this library to give any more suggestions.)

bmlis commented 7 years ago

Bump, will this be addressed in any way? Should we just create migrations manually?

NilsJPWerner commented 7 years ago

I have made a quick pr to fix this problem: https://github.com/klen/peewee_migrate/pull/56