I want to define a specific schema for a 'model' using flask-sqlalchemy. When you create a table object in sqlalchemy itself it has a parameter to pass for schema name.
How do I do this in flask-sqlalchemy?
I want to define a specific schema for a 'model' using flask-sqlalchemy. When you create a table object in sqlalchemy itself it has a parameter to pass for schema name.
How do I do this in flask-sqlalchemy?
This is how I did it but I am also looking for a better way if possible -
db = flask.ext.sqlalchemy.SQLAlchemy(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'your_default_schema_db_uri'
class Entity():
__table_args__ = {
'schema': 'schema_name'
}
# common columns below
class TableA(Entity, db.Model):
# This belongs to Default schema, it doesn't need specify __bind_key__
__table_args__ = {'schema' : Entity.__table_args__["schema"],
'comment': 'TableA'}
class TableB(Entity, db.Model):
# This belongs to other_schema
__table_args__ = {'schema' : Entity.__table_args__["schema"],
'comment': 'TableA'}