relation "django_migrations" already exists

Viewed 446

I am using Django-tenant-schemas for assigning tenants to their own schema. I had a migration issue awhile back and now there is something residual left from the failed creation of a tenant on it's own schema. This schema is called tiger.

To give an idea how it is set up; there is some data which is public and exists on the public schema (such as users and companies) but everything else is tenant specific and on its own schema.

This is how I run migrations:

(venv) david@clearpath:~/clearpath_project$ python manage.py migrate_schemas

[standard:public] === Starting migration
[standard:public] Operations to perform:
[standard:public]   Apply all migrations: admin, auth, categories, companies, contenttypes, employees, invite, memos, notifications, phone_verify, quiz, sessions, videos
[standard:public] Running migrations:
[standard:public]   No migrations to apply.

[1/5 (20%) standard:clearpath] === Starting migration
[1/5 (20%) standard:clearpath] Operations to perform:
[1/5 (20%) standard:clearpath]   Apply all migrations: admin, auth, categories, companies, contenttypes, employees, invite, memos, notifications, phone_verify, quiz, sessions, videos
[1/5 (20%) standard:clearpath] Running migrations:
[1/5 (20%) standard:clearpath]   No migrations to apply.
[2/5 (40%) standard:c1] === Starting migration
[2/5 (40%) standard:c1] Operations to perform:
[2/5 (40%) standard:c1]   Apply all migrations: admin, auth, categories, companies, contenttypes, employees, invite, memos, notifications, phone_verify, quiz, sessions, videos
[2/5 (40%) standard:c1] Running migrations:
[2/5 (40%) standard:c1]   No migrations to apply.
[3/5 (60%) standard:aces] === Starting migration
[3/5 (60%) standard:aces] Operations to perform:
[3/5 (60%) standard:aces]   Apply all migrations: admin, auth, categories, companies, contenttypes, employees, invite, memos, notifications, phone_verify, quiz, sessions, videos
[3/5 (60%) standard:aces] Running migrations:
[3/5 (60%) standard:aces]   No migrations to apply.
[4/5 (80%) standard:tiger] === Starting migration
[4/5 (80%) standard:tiger] Operations to perform:
[4/5 (80%) standard:tiger]   Apply all migrations: admin, auth, categories, companies, contenttypes, employees, invite, memos, notifications, phone_verify, quiz, sessions, videos
[4/5 (80%) standard:tiger] Running migrations:

At schema tiger it fails and says:

Note: this is only the beginning part of the traceback

Traceback (most recent call last):
  File "/home/david/clearpath_project/venv/lib/python3.7/site-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
psycopg2.errors.DuplicateTable: relation "django_migrations" already exists

I have tried deleting the schema using psql DROP SCHEMA tiger CASCADE; but this does not help. I believe the issue is because the tenant still exists in the public schema - but I could be wrong.

I need to keep the data so wiping the db is not an option.

Any thoughts on how I can try to fix this?

0 Answers
Related