首页 > 解决方案 > Authenticating user problem with django-tenant-schema

问题描述

I want to have admin module available to tenants (using django-tenant-schema). My apps section of settings.py:

# Application definition
SHARED_APPS = (
    'tenant_schemas',  # mandatory, should always be before any django app
    'customers', # you must list the app where your tenant model resides in

    # 'django.contrib.sites',

    # everything below here is optional


)

TENANT_APPS = (
    'django.contrib.contenttypes',

    # your tenant-specific apps
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

INSTALLED_APPS = (
    'tenant_schemas',  # mandatory, should always be before any django app

    'customers',
    # 'django.contrib.sites', #using this will cause error - see my stackoverflow question
    'django.contrib.auth',
    'django.contrib.admin',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

I have set up 2 schemas (tenant1 and public). Created superuser and can see that superuser is created within tenant1 schema. However when trying to log in at tenant1.domain.com/admin, getting login screen but after entering credentials keep getting:

ProgrammingError at /admin/login/ relation "auth_user" does not exist

Looks like it is not picking up my tenant1 schema? What I have to change in configuration?

标签: django

解决方案


Make sure tenant middleware is installed.

It's responsible for negotiating which tenant is called and connecting to the right schemas.


推荐阅读