Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New tenant model is not creating relations in non-public schema with multiple databases #669

Open
khixer opened this issue May 12, 2021 · 0 comments

Comments

@khixer
Copy link

khixer commented May 12, 2021

Hi,

Use Case:

I'm using this package for quite some time. We encountered a use case in which we have to introduce a new database. Adding a new schema won't suffice so we added another DB with multi-tenancy. Therefore, having two databases operating on a semi-isolated approach. Now, I'm facing an issue regarding the migration of a particular schema in the non-default database.

Code
Two DB's are as follows:

"default": {
        "ENGINE": "tenant_schemas.postgresql_backend",
        "NAME": os.environ.get("DB_NAME", "****"),
        "USER": os.environ.get("DB_USER", "****"),
        "PASSWORD": "****",
    },
"non_default": {
        "ENGINE": "tenant_schemas.postgresql_backend",
        "NAME": os.environ.get("DB_NAME", "****"),
        "USER": os.environ.get("DB_USER", "****"),
        "PASSWORD": "***",
    }

Initially, I ran this command: python manage.py migrate_schemas --database=non_default. It creates necessary tables in the public schema

Now, when I'm trying to do: python manage.py migrate_schemas --database=non_default --schema=nds. Django is unable to find the schema nds. Also,

I created the tenant via ORM as suggested in the docs but it didn't create the tenant schema. Creating schema manually through create schema nds from psql didn't work either.

ORM code

tenant = Company(domain_url='xyz.nds.domain-url.com', schema_name='nds', name='nds')
tenant.save(using="non_default")

Didn't run any migration

Company.objects.using("non_default") shows the tenant model but no relations.

Any help would be highly appreciated.

Thanks!

@khixer khixer changed the title Migrations are not creating table in specific schema with multiple databases New tenant model is not creating relations in non-public schema with multiple databases May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant