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

Is there any way to migrate tenant app which previous was only shared? #479

Open baterson opened 7 years ago

baterson commented 7 years ago

Hi I have setup like this:

SHARED_APPS = (
    'tenant_schemas',
    # django apps here

    'apps.users',
)

TENANT_APPS = (
    'django.contrib.contenttypes',
    'django.contrib.auth',
)

After running makemigrations and migrate_schemas, apps.users is accessible only in my public schema like I expect. But then I realize that I need app users in my tenants schemas too. I put it to TENANT_APPS and run makemigrations again. But django did not find any change in my apps.
Is there any way to move app from shared to tenants? Or my only choice is to delete tenant schema and make migrations again?

noirifrop commented 7 years ago

I just had the exact same situation. In the SHARED_APPS I forgot to add 'django.contrib.sessions' and once it has been added, python manage.py migrate_schemas kept saying that there are no changes to be applied, however django_session table was not in the schema

When I've inspected .django_migrations it had an entry for sessions but since the table has not been created I'm guessing that migrate_schemas somehow 'fake' applied the migration?

Running DELETE FROM <schema>.django_migrations WHERE app='sessions'; and then python manage.py migrate_schemas resulted with

Applying sessions.0001_initial...

which ultimately solved the problem

DAVIS-PYTH commented 2 years ago

the solution by @noirifrop ultimately solved this issue