Closed mikebski closed 3 months ago
I don't know what you mean by "set the schema", but if you mean changing it from the default ("public") to something else, you should be able to just:
ModelClass._meta.schema = 'schema_name'
You'll need to do this for all the models you wish to modify.
You can also use the SubclassAwareMetadata
to make this process more simple, e.g.:
class Base(Model):
class Meta:
model_metadata_class = SubclassAwareMetadata
database = db
...
# Apply the schema to all subclasses of `Base`.
def set_schema(name):
def _update(m):
m._meta.schema = name
return _update
Base._meta.map_models(set_schema('schema_name'))
(note - edited to fix typo in snippet)
How can I dynamically bind a schema, similar to binding a model: