bernardopires / django-tenant-schemas

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

Schema Deletion #678

Closed khixer closed 2 years ago

khixer commented 2 years ago

Hi,

I just wanted to know how to drop a schema. I've deleted the record in the tenant model via Django ORM but it seems that schema still exists in the DB (confirmed via psql).

I've multiple schemas and I'm getting this error `psycopg2.errors.DuplicateTable: relation "django_migrations" already exists. I've tried running the fake migration as mentioned in many StackOverflow links. Also, I've deleted the tenant record but still, it throws an error while running migrate_schemas for that schema.

Getting error after this:

=== Running migrate for schema somethingabouttesting
psycopg2.errors.DuplicateTable: relation "django_migrations" already exists

I've deleted the somethingabouttesting schema and tried again, but still, it's showing the same error.

Any help would be appreciated.

mtthwsar commented 2 years ago

You can drop the schema from the Django dbshell.

python manage.py dbshell

then

DROP SCHEMA somethingabouttesting CASCADE;