klen / peewee_migrate

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

peewee.ProgrammingError: column of relation already exists #94

Open rominf opened 6 years ago

rominf commented 6 years ago

I have a model with a few fields. In the next version of my program, I want to add another field. I add it to the model class and write a migration with migrator.add_fields call. Everything is fine if I run the program with an empty database or if I migrate the database from the previous version. But I run migrations on the database of the last version which had no migrations I get the exception:

peewee.ProgrammingError: column of relation already exists

How do I handle this situation? Is there any way to suppress the exception or to check the field existence without executing SQL (I want my migrations to be DBMS independent)?

anatoly-scherbakov commented 3 years ago

@rominf this is very necroposty of me, but did you find a solution which would be better than this?

    try:
        migrator.add_columns(
            model=DBCampaign,
            state_machine_arn=DBCampaign.state_machine_arn,
        )
    except ProgrammingError as err:
        if str(err).endswith('already exists'):
            logger.info('Skipping adding a column that already exists: %s', err)
        else:
            raise
rominf commented 3 years ago

Even if I did, I don't remember it.

anatoly-scherbakov commented 3 years ago

I see. Thanks for replying!