Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relation already exists error when using Model's create_table with fail silently option #1314

Closed
Tumetsu opened this issue Jul 12, 2017 · 1 comment

Comments

@Tumetsu
Copy link

Tumetsu commented Jul 12, 2017

Hello, I'm using peewee with peewee_migrate library and encountered a problem today.
When I try to run my migrations, I get error

peewee.ProgrammingError: relation "migratehistory" already exists

More info in issue I posted to peewee_migrate's repo: klen/peewee_migrate#51
I investigated the reason and found the following. In the peewee_migrate, the migration history is created in a following function:

@cached_property
    def model(self):
        """Initialize and cache MigrationHistory model."""
        MigrateHistory._meta.database = self.database
        MigrateHistory._meta.db_table = self.migrate_table
        MigrateHistory.create_table(True)
        return MigrateHistory

Note the create_table call. After tinkering around a bit I noticed that the next version works:

@cached_property
    def model(self):
        """Initialize and cache MigrationHistory model."""
        MigrateHistory._meta.database = self.database
        MigrateHistory._meta.db_table = self.migrate_table
        self.database.create_table(MigrateHistory, safe=True)
        return MigrateHistory

You see I use database object's class method instead of Models.

This led me to wonder if the problem is actually in peewee and model's create_table won't work as expected. Of course it might be an issue with peewee_migrate (and therefore not really your business) as I originally suspected but I'd like to hear if you have any idea why the original code won't work or if there is indeed a bug in peewee :)

Finally here is link to peewee_migrate's file containing the snippets above: https://github.com/klen/peewee_migrate/blob/develop/peewee_migrate/router.py

And thanks by the way for creating peewee!

@Tumetsu
Copy link
Author

Tumetsu commented Jul 12, 2017

Found the problem which was in peewee_migrate. So nothing to see here. More information for curious: klen/peewee_migrate#51

@Tumetsu Tumetsu closed this as completed Jul 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant