bernardopires / django-tenant-schemas

Tenant support for Django using PostgreSQL schemas.
https://django-tenant-schemas.readthedocs.org/en/latest/
MIT License
1.46k stars 424 forks source link

How to create dynamic models and migrate into particular schema #611

Closed marimuthuinchennai closed 4 years ago

marimuthuinchennai commented 4 years ago

model = type(name, (models.Model,), attrs)

the above is my dynamic model

i am trying this command to execute to create table

call_command('loaddata','model',schema_name=SchemaName,verbosity=0,)

it seems this error for me how to resolve, is it correct way?

jeroenbrouwer commented 4 years ago

Use schema_context, tenant_context or manually set the connection to the right schema. See: https://django-tenant-schemas.readthedocs.io/en/latest/use.html#utils

marimuthuinchennai commented 4 years ago

Use schema_context, tenant_context or manually set the connection to the right schema. See: https://django-tenant-schemas.readthedocs.io/en/latest/use.html#utils

thanks for your reply

Instaed of using tenant command i had used this command below thanks for your reply

siteName = type(siteName, (models.Model,), attrs) with connection.schema_editor() as schema_editor: schema_editor.create_model(ModelName)