Я пытаюсь настроить приложение SaaS на основе Wagtail, используя django-tenants
, чтобы иметь единую схему Postgres для каждого клиента.
Я строго установил django-арендаторов следуя документации ReadTheDocs, мне удалось успешно перенести схему publi c.
Однако, когда я добавляю первого клиента через Django Admin, миграция wagtailcore.0037_set_page_owner_editable
завершается неудачно со следующей ошибкой:
tenants_1 | Applying wagtailcore.0037_set_page_owner_editable...
db_1 | ERROR: cannot ALTER TABLE "wagtailcore_page" because it has pending trigger events
db_1 | STATEMENT: SET CONSTRAINTS "wagtailcore_page_owner_id_fbf7c332_fk_auth_user_id" IMMEDIATE; ALTER TABLE "wagtailcore_page" DROP CONSTRAINT "wagtailcore_page_owner_id_fbf7c332_fk_auth_user_id"
db_1 | ERROR: cannot DROP TABLE "wagtailcore_groupcollectionpermission" because it has pending trigger events
db_1 | STATEMENT: DROP SCHEMA "tenant_galilei" CASCADE
tenants_1 | Internal Server Error: /django-admin/customers/client/add/
tenants_1 | Traceback (most recent call last):
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
tenants_1 | return self.cursor.execute(sql, params)
tenants_1 | psycopg2.errors.ObjectInUse: cannot ALTER TABLE "wagtailcore_page" because it has pending trigger events
tenants_1 | Internal Server Error: /django-admin/customers/client/add/
tenants_1 | Traceback (most recent call last):
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
tenants_1 | return self.cursor.execute(sql, params)
tenants_1 | psycopg2.errors.ObjectInUse: cannot ALTER TABLE "wagtailcore_page" because it has pending trigger events
tenants_1 |
tenants_1 |
tenants_1 | The above exception was the direct cause of the following exception:
tenants_1 |
tenants_1 | Traceback (most recent call last):
tenants_1 | File "/app/django_tenants/models.py", line 103, in save
tenants_1 | self.create_schema(check_if_exists=True, verbosity=verbosity)
tenants_1 | File "/app/django_tenants/models.py", line 194, in create_schema
tenants_1 | verbosity=verbosity)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 148, in call_command
tenants_1 | return command.execute(*args, **defaults)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
tenants_1 | output = self.handle(*args, **options)
tenants_1 | File "/app/django_tenants/management/commands/migrate_schemas.py", line 63, in handle
tenants_1 | executor.run_migrations(tenants=tenants)
tenants_1 | File "/app/django_tenants/migration_executors/standard.py", line 15, in run_migrations
tenants_1 | run_migrations(self.args, self.options, self.codename, schema_name, idx=idx, count=len(tenants))
tenants_1 | File "/app/django_tenants/migration_executors/base.py", line 36, in run_migrations
tenants_1 | MigrateCommand(stdout=stdout, stderr=stderr).execute(*args, **options)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
tenants_1 | output = self.handle(*args, **options)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
tenants_1 | res = handle_func(*args, **kwargs)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 234, in handle
tenants_1 | fake_initial=fake_initial,
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/migrations/executor.py", line 117, in migrate
tenants_1 | state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
tenants_1 | state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
tenants_1 | state = migration.apply(state, schema_editor)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/migrations/migration.py", line 124, in apply
tenants_1 | operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/migrations/operations/fields.py", line 249, in database_forwards
tenants_1 | schema_editor.alter_field(from_model, from_field, to_field)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 535, in alter_field
tenants_1 | old_db_params, new_db_params, strict)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/postgresql/schema.py", line 124, in _alter_field
tenants_1 | new_db_params, strict,
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 552, in _alter_field
tenants_1 | self.execute(self._delete_fk_sql(model, fk_name))
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 137, in execute
tenants_1 | cursor.execute(sql, params)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 99, in execute
tenants_1 | return super().execute(sql, params)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 67, in execute
tenants_1 | return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
tenants_1 | return executor(sql, params, many, context)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
tenants_1 | return self.cursor.execute(sql, params)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
tenants_1 | raise dj_exc_value.with_traceback(traceback) from exc_value
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
tenants_1 | return self.cursor.execute(sql, params)
tenants_1 | django.db.utils.OperationalError: cannot ALTER TABLE "wagtailcore_page" because it has pending trigger events
tenants_1 |
tenants_1 |
tenants_1 | During handling of the above exception, another exception occurred:
tenants_1 |
tenants_1 | Traceback (most recent call last):
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 82, in _execute
tenants_1 | return self.cursor.execute(sql)
tenants_1 | psycopg2.errors.ObjectInUse: cannot DROP TABLE "wagtailcore_groupcollectionpermission" because it has pending trigger events
tenants_1 |
tenants_1 |
tenants_1 | The above exception was the direct cause of the following exception:
tenants_1 |
tenants_1 | Traceback (most recent call last):
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
tenants_1 | response = get_response(request)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
tenants_1 | response = self.process_exception_by_middleware(e, request)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
tenants_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/options.py", line 606, in wrapper
tenants_1 | return self.admin_site.admin_view(view)(*args, **kwargs)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
tenants_1 | response = view_func(request, *args, **kwargs)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
tenants_1 | response = view_func(request, *args, **kwargs)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/sites.py", line 223, in inner
tenants_1 | return view(request, *args, **kwargs)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1645, in add_view
tenants_1 | return self.changeform_view(request, None, form_url, extra_context)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/decorators.py", line 45, in _wrapper
tenants_1 | return bound_method(*args, **kwargs)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
tenants_1 | response = view_func(request, *args, **kwargs)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1529, in changeform_view
tenants_1 | return self._changeform_view(request, object_id, form_url, extra_context)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1572, in _changeform_view
tenants_1 | self.save_model(request, new_object, form, not add)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1088, in save_model
tenants_1 | obj.save()
tenants_1 | File "/app/django_tenants/models.py", line 108, in save
tenants_1 | self.delete(force_drop=True)
tenants_1 | File "/app/django_tenants/models.py", line 153, in delete
tenants_1 | self._drop_schema(force_drop)
tenants_1 | File "/app/django_tenants/models.py", line 140, in _drop_schema
tenants_1 | cursor.execute('DROP SCHEMA "%s" CASCADE' % self.schema_name)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 99, in execute
tenants_1 | return super().execute(sql, params)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 67, in execute
tenants_1 | return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
tenants_1 | return executor(sql, params, many, context)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
tenants_1 | return self.cursor.execute(sql, params)
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
tenants_1 | raise dj_exc_value.with_traceback(traceback) from exc_value
tenants_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 82, in _execute
tenants_1 | return self.cursor.execute(sql)
tenants_1 | django.db.utils.OperationalError: cannot DROP TABLE "wagtailcore_groupcollectionpermission" because it has pending trigger events
tenants_1 |
Ниже вы можете найти код миграции Wagtail:
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-05-03 12:05
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('wagtailcore', '0036_populate_page_last_published_at'),
]
operations = [
migrations.AlterField(
model_name='page',
name='owner',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='owned_pages', to=settings.AUTH_USER_MODEL, verbose_name='owner'),
),
]
Мое приложение в настоящее время работает со следующими версиями требований:
Django==2.2.13
wagtail==2.8.2
django-tenants==3.1.0
Любая помощь приветствуется: -)