django-tenant-schemas
django-tenant-schemas copied to clipboard
Unable to migrate for tenant app django-helpdesk
Tech stack: Django 2.2, Python 3.6.7
django-tenant-schema is working perfectly and fine with all my custom django apps (TENANT APPS). You can check https://hygull.github.io/try-django-tenant-schemas/.
Now I took the above example as reference and tried to install 3rd party apps (TENANT APPS).
3rd party django app like django-db-mailer (TENANT APP) is also working fine.
Today, I tried to install another 3rd party app django-helpdesk (TENANT APP). And got exceptions while running python manage.py makemigrations --tenant
.
So, after that I deleted my migrations from each app cutomers
, users
, books
, re-created database, added tenant model, ran makemigrations
, migrate_schemas
, created public tenant. These all worked fine.
I opened django shell, created public tenant, saved it public.save()
. This also worked fine.
The main failed statement was tenant1.save()
that you can find in the below log history with statements.
(venv3.6.7) ➜ src git:(helpdesk) ✗ python manage.py shell
Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 03:02:14)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from customers.models import Client
>>>
>>> # create your public tenant
>>> public = Client(domain_url='my-domain.com', # don't add your port or www here! on a local server you'll want to use localhost here
... schema_name='public',
... name='Schemas Inc.',
... paid_until='2016-12-05',
... on_trial=False)
>>>
>>> public.save()
>>>
>>> tenant1 = Client(domain_url='tenant1.my-domain.com', # don't add your port or www here!
... schema_name='tenant1',
... name='Tenant1',
... paid_until='2014-12-05',
... on_trial=True)
>>>
>>> tenant1.save() # migrate_schemas
[standard:tenant1] === Running migrate for schema tenant1
[standard:tenant1] Operations to perform:
[standard:tenant1] Apply all migrations: admin, auth, books, contenttypes, customers, helpdesk, sessions, sites, users
[standard:tenant1] Running migrations:
[standard:tenant1] Applying contenttypes.0001_initial...
[standard:tenant1] OK
[standard:tenant1] Applying auth.0001_initial...
[standard:tenant1] OK
[standard:tenant1] Applying admin.0001_initial...
[standard:tenant1] OK
[standard:tenant1] Applying admin.0002_logentry_remove_auto_add...
[standard:tenant1] OK
[standard:tenant1] Applying admin.0003_logentry_add_action_flag_choices...
[standard:tenant1] OK
[standard:tenant1] Applying contenttypes.0002_remove_content_type_name...
[standard:tenant1] OK
[standard:tenant1] Applying auth.0002_alter_permission_name_max_length...
[standard:tenant1] OK
[standard:tenant1] Applying auth.0003_alter_user_email_max_length...
[standard:tenant1] OK
[standard:tenant1] Applying auth.0004_alter_user_username_opts...
[standard:tenant1] OK
[standard:tenant1] Applying auth.0005_alter_user_last_login_null...
[standard:tenant1] OK
[standard:tenant1] Applying auth.0006_require_contenttypes_0002...
[standard:tenant1] OK
[standard:tenant1] Applying auth.0007_alter_validators_add_error_messages...
[standard:tenant1] OK
[standard:tenant1] Applying auth.0008_alter_user_username_max_length...
[standard:tenant1] OK
[standard:tenant1] Applying auth.0009_alter_user_last_name_max_length...
[standard:tenant1] OK
[standard:tenant1] Applying auth.0010_alter_group_name_max_length...
[standard:tenant1] OK
[standard:tenant1] Applying auth.0011_update_proxy_permissions...
[standard:tenant1] OK
[standard:tenant1] Applying books.0001_initial...
[standard:tenant1] OK
[standard:tenant1] Applying customers.0001_initial...
[standard:tenant1] OK
[standard:tenant1] Applying helpdesk.0001_initial...
[standard:tenant1] OK
[standard:tenant1] Applying helpdesk.0002_populate_usersettings...
[standard:tenant1] OK
[standard:tenant1] Applying helpdesk.0003_initial_data_import...
[standard:tenant1] OK
[standard:tenant1] Applying helpdesk.0004_add_per_queue_staff_membership...
[standard:tenant1] OK
[standard:tenant1] Applying helpdesk.0005_queues_no_null...
[standard:tenant1] OK
[standard:tenant1] Applying helpdesk.0006_email_maxlength...
[standard:tenant1] OK
[standard:tenant1] Applying helpdesk.0007_max_length_by_integer...
[standard:tenant1] OK
[standard:tenant1] Applying helpdesk.0008_extra_for_permissions...
[standard:tenant1] OK
[standard:tenant1] Applying helpdesk.0009_migrate_queuemembership...
[standard:tenant1] OK
[standard:tenant1] Applying helpdesk.0010_remove_queuemembership...
[standard:tenant1] OK
[standard:tenant1] Applying helpdesk.0011_admin_related_improvements...
Traceback (most recent call last):
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "helpdesk_queue_slug_3b3429c3_like" already exists
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/tenant_schemas/models.py", line 71, in save
self.create_schema(check_if_exists=True, verbosity=verbosity)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/tenant_schemas/models.py", line 118, in create_schema
verbosity=verbosity)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/core/management/__init__.py", line 148, in call_command
return command.execute(*args, **defaults)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/tenant_schemas/management/commands/migrate_schemas.py", line 53, in handle
executor.run_migrations(tenants=tenants)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/tenant_schemas/migration_executors/base.py", line 61, in run_migrations
self.run_tenant_migrations(tenants)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/tenant_schemas/migration_executors/standard.py", line 9, in run_tenant_migrations
run_migrations(self.args, self.options, self.codename, schema_name)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/tenant_schemas/migration_executors/base.py", line 31, in run_migrations
MigrateCommand(stdout=stdout, stderr=stderr).execute(*args, **options)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 234, in handle
fake_initial=fake_initial,
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 249, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 535, in alter_field
old_db_params, new_db_params, strict)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/postgresql/schema.py", line 129, in _alter_field
self.execute(like_index_statement)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 137, in execute
cursor.execute(sql, params)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/utils.py", line 99, in execute
return super().execute(sql, params)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "helpdesk_queue_slug_3b3429c3_like" already exists
>>>
And, when I execute python manage.py migrate_schemas --tenant
after the above steps, I got this exception.
(venv3.6.7) ➜ src git:(helpdesk) ✗ python manage.py migrate_schemas --tenant
[standard:tenant1] === Running migrate for schema tenant1
[standard:tenant1] Operations to perform:
[standard:tenant1] Apply all migrations: admin, auth, books, contenttypes, customers, helpdesk, sessions, sites, users
[standard:tenant1] Running migrations:
Traceback (most recent call last):
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "django_migrations" already exists
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 67, in ensure_schema
editor.create_model(self.Migration)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 307, in create_model
self.execute(sql, params or None)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 137, in execute
cursor.execute(sql, params)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/utils.py", line 99, in execute
return super().execute(sql, params)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "django_migrations" already exists
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/tenant_schemas/management/commands/migrate_schemas.py", line 53, in handle
executor.run_migrations(tenants=tenants)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/tenant_schemas/migration_executors/base.py", line 61, in run_migrations
self.run_tenant_migrations(tenants)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/tenant_schemas/migration_executors/standard.py", line 9, in run_tenant_migrations
run_migrations(self.args, self.options, self.codename, schema_name)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/tenant_schemas/migration_executors/base.py", line 31, in run_migrations
MigrateCommand(stdout=stdout, stderr=stderr).execute(*args, **options)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 234, in handle
fake_initial=fake_initial,
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/migrations/executor.py", line 91, in migrate
self.recorder.ensure_schema()
File "/Users/hygull/Desktop/try-django-tenant-schemas/venv3.6.7/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 69, in ensure_schema
raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (relation "django_migrations" already exists
)
Thank you very much.
I will wait for your response.
I don't want to look at your code or django-helpdesk's code.
Just want the confirmation if really this is an issue or my fault.
I have already tried 3-4 times (from scratch).