borisbrue / wagtail-tenants

wagtail_tenants is a Django/Wagtail app to provide multitenancy to your wagtail project.
25 stars 8 forks source link

Error while migrating the database. #6

Closed xeroticikot closed 1 year ago

xeroticikot commented 1 year ago

Below is my apps settings -

SHARED_APPS = (
    'wagtail_tenants.customers',
    'wagtail_tenants',
    'wagtail.contrib.forms',
    "wagtail_tenants.users",
    "wagtail.users",
    "home",
    "search",
)

TENANT_APPS = (
    "django.contrib.contenttypes",
    "wagtail.contrib.redirects",
    "wagtail.embeds",
    "wagtail.sites",
    "wagtail.users",
    "wagtail.snippets",
    "wagtail.documents",
    "wagtail.images",
    "wagtail.search",
    "wagtail.admin",
    "wagtail",
    "modelcluster",
    "taggit",
    "django.contrib.admin",
    "django.contrib.auth",
    # "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "wagtail_tenants.users",
    # "wagtail.users",
)

INSTALLED_APPS = list(SHARED_APPS) + [
    app for app in TENANT_APPS if app not in SHARED_APPS
]

Below is the traceback from running "migrate_schemas --shared" command -

E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\wagtail_tenants\wagtail_hooks.py:3: RemovedInWagtail50Warning: Importing from
 wagtail.core.hooks is deprecated. Use wagtail.hooks instead. See https://docs.wagtail.org/en/stable/releases/3.0.html#chan
ges-to-module-paths
  from wagtail.core import hooks
E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\wagtail_tenants\users\views\users.py:16: RemovedInWagtail50Warning: Importing
 from wagtail.core.log_actions is deprecated. Use wagtail.log_actions instead. See https://docs.wagtail.org/en/stable/relea
ses/3.0.html#changes-to-module-paths
  from wagtail.core.log_actions import log
E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\wagtail\core\models\__init__.py:46: RemovedInWagtail50Warning: Importing from
 wagtail.core.models.audit_log is deprecated. Use wagtail.models.audit_log instead. See https://docs.wagtail.org/en/stable/
releases/3.0.html#changes-to-module-paths
  from .audit_log import (  # noqa
E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\wagtail\core\models\__init__.py:52: RemovedInWagtail50Warning: Importing from
 wagtail.core.models.collections is deprecated. Use wagtail.models.collections instead. See https://docs.wagtail.org/en/sta
ble/releases/3.0.html#changes-to-module-paths
  from .collections import (  # noqa
E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\wagtail\core\models\__init__.py:62: RemovedInWagtail50Warning: Importing from
 wagtail.core.models.copying is deprecated. Use wagtail.models.copying instead. See https://docs.wagtail.org/en/stable/rele
ases/3.0.html#changes-to-module-paths
  from .copying import _copy, _copy_m2m_relations, _extract_field_data  # noqa
E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\wagtail\core\models\__init__.py:63: RemovedInWagtail50Warning: Importing from
 wagtail.core.models.i18n is deprecated. Use wagtail.models.i18n instead. See https://docs.wagtail.org/en/stable/releases/3
.0.html#changes-to-module-paths
  from .i18n import (  # noqa
E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\wagtail\core\models\__init__.py:72: RemovedInWagtail50Warning: Importing from
 wagtail.core.models.sites is deprecated. Use wagtail.models.sites instead. See https://docs.wagtail.org/en/stable/releases
/3.0.html#changes-to-module-paths
  from .sites import Site, SiteManager, SiteRootPath  # noqa
E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\wagtail_tenants\panels.py:3: RemovedInWagtail50Warning: Importing from wagtai
l.core.models is deprecated. Use wagtail.models instead. See https://docs.wagtail.org/en/stable/releases/3.0.html#changes-t
o-module-paths
  from wagtail.core.models import UserPagePermissionsProxy
[standard:public] === Starting migration
[standard:public] Operations to perform:
[standard:public]   Apply all migrations: admin, auth, contenttypes, customers, home, sessions, taggit, users, wagtail_tena
nts, wagtailadmin, wagtailcore, wagtaildocs, wagtailembeds, wagtailforms, wagtailimages, wagtailredirects, wagtailsearch, w
agtailusers
[standard:public] Running migrations:
[standard:public]   Applying wagtail_tenants.0001_initial...
Traceback (most recent call last):
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\db\backends\utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "auth_group" does not exist

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "E:\WORKPLACE\WAGMTTEST\mtest\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_comman
d_line
    utility.execute()
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\core\management\__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\core\management\base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\core\management\base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django_tenants\management\commands\migrate_schemas.py", line 63, in h
andle
    executor.run_migrations(tenants=[self.PUBLIC_SCHEMA_NAME])
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django_tenants\migration_executors\standard.py", line 11, in run_migr
ations
    run_migrations(self.args, self.options, self.codename, self.PUBLIC_SCHEMA_NAME)
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django_tenants\migration_executors\base.py", line 57, in run_migratio
ns
    migrate_command_class(stdout=stdout, stderr=stderr).execute(*args, **options)
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\core\management\base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\core\management\base.py", line 96, in wrapped
    res = handle_func(*args, **kwargs)
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\core\management\commands\migrate.py", line 349, in handle
    post_migrate_state = executor.migrate(
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\db\migrations\executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\db\migrations\executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\db\migrations\executor.py", line 255, in apply_migration
    migration_recorded = True
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\db\backends\base\schema.py", line 164, in __exit__
    self.execute(sql)
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\db\backends\base\schema.py", line 199, in execute
    cursor.execute(sql, params)
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\db\backends\utils.py", line 102, in execute
    return super().execute(sql, params)
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\db\backends\utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\db\backends\utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\db\backends\utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\db\utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "E:\WORKPLACE\WAGMTTEST\wenv\lib\site-packages\django\db\backends\utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "auth_group" does not exist
borisbrue commented 1 year ago

hi @xeroticikot,

the docu is not good at this point. Sorry for that. I will update it with my next iteration. For the meantime, you can try this:

SHARED_APPS = (
    'wagtail_tenants.customers',
    'wagtail_tenants',
    "wagtail.contrib.forms",
    "wagtail.contrib.redirects",
    "wagtail.embeds",
    "wagtail.sites",
    "wagtail.users",
    "wagtail.snippets",
    "wagtail.documents",
    "wagtail.images",
    "wagtail.search",
    "wagtail.admin",
    "wagtail_tenants.users",
    "wagtail",
    "modelcluster",
    "taggit",

    "django.contrib.staticfiles",
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",

    "wagtail.api.v2",
    "rest_framework",
)

TENANT_APPS = (
    'wagtail_tenants',
    "wagtail.contrib.forms",
    "wagtail.contrib.redirects",
    "wagtail.embeds",
    "wagtail.sites",
    "wagtail.users",
    "wagtail.snippets",
    "wagtail.documents",
    "wagtail.images",
    "wagtail.search",
    "wagtail.admin",
    "wagtail_tenants.users",
    "wagtail",
    "modelcluster",
    "taggit",
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
)

I use it that way and it will work. I stumbled upon a case where some issues occur within the Object/Model/Snippet Reference Index.

If you have all Wagtail Apps in the TENANT_APPS, it will try to create a reference in the public schema (because of signals), which will give you a “Table not found for ContentTypes”.The Solution: You have to set wagtail_reference_index_ignore = True on your Tenant and Domain Model, and every other Model in your SHARED_APPS.

as far as you don't plan to use the snippets feature it will be no problem for you. I still need some time to provide a signal-flow within the tenant to not go to the public schema