问题
Say I have a Postgres database with two different schema's, one called public
and one called development
. I know at the class level I can set __table_args__ = {"schema":"schema_name"}
for each model, but if I wanted to switch from development to prod. wouldn't I haven't to update all my models?
Is there a way to set the schema for the dev and prod schemas in flask? Or should I just create another database as a dev database and just backup the prod database to the development database?
回答1:
Assuming there's something in the config along the lines of PRODUCTION = False/True, then you should be able to set the schema by adding into the models:
if app.config['PRODUCTION']:
db_schema = 'public'
else:
db_schema = 'development'
And then update your table_args:
__table_args__ = {'schema': db_schema }
来源:https://stackoverflow.com/questions/49409691/flask-sqlalchemy-acess-different-schema