question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot specify schema with PostgresqlMigrator

See original GitHub issue

I’m trying to use playhouse.migrate to modify the database according to the model changes, but it seems I cannot specify the PostgreSQL schema of the table that I need to alter.

My model looks like this:

db = PostgresqlDatabase(...)

class MyTable(Model):
    title = CharField()
    class Meta:
        database = db 
        db_table = 'table_name'
        schema = 'my_schema'

But if I run migration code like the following:

migrator = PostgresqlMigrator(db)
new_field = CharField(default="")
migrate(
    migrator.add_column(MyTable._meta.db_table, 'new_field', new_field),
)

, I get this error:

peewee.ProgrammingError: relation "table_name" does not exist

How can I tell the migrator that it should alter the table table_name in the schema my_schema ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
coleifercommented, Feb 9, 2018

Rather than modify all the APIs to support a schema parameter, I added a method which you can use to set the search path for subsequent operations. e.g.


title_field = TextField(default='')
migrate(
    migrator.set_search_path('my_schema'),
    migrator.add_column('some_table', 'title', title_field),
)
0reactions
albireoxcommented, Feb 7, 2018

Yep, that seems to fix the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation: 15: 5.9. Schemas - PostgreSQL
A PostgreSQL database cluster contains one or more named databases. ... By default, users cannot access any objects in schemas they do not...
Read more >
Dbcontext not able to migrate because schema does not exist?
DbContext is being created, but once the migrations is being called i get an error stating that the schema, does not exist? which...
Read more >
Zero-downtime Postgres schema migrations need this
Deploying DB schema changes in heavily loaded systems is challenging. In this article, we explore one of the challenges - how to avoid ......
Read more >
PostgreSQL error when migrating from 5.39.0 to 6.0.0
Summary errors during the database schema migration of the PostgreSQL database when starting up the 6.0.0 version with a PostgreSQL 13.4 ...
Read more >
PostgreSQL schema-change gotchas - Medium
Add the new column (without the default value). · Set the default value on the column. This operation locks the table too, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found