Closed rkotcherr closed 6 years ago
Ok, a made a little progress.
In Django 2.1, MIDDLEWARE_CLASSES should be MIDDLEWARE like this:
MIDDLEWARE = (
'tenant_schemas.middleware.SuspiciousTenantMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
Now I'm successfully seeing
Indicating that no errors have occurred. The app seems to "think" it's connecting to the correct tenants, but in the end I'm still left with only 1 schema:
And all users are stored directly into the public schema.
Thoughts?
Just wanted to write to clarify for anybody else who runs across this issue. My problem was that, although I read the docs, I had just manually entered customers into the database. If you're running across the issue I describe above, be sure to add clients as described. ☹️
Are there any successful cases
How do you add tenant?
@Regretss You have to create it via the shell. Create a public schema, and then save it. There's an on-save hook that'll create the schema for you. Please read the "Getting started" part of the docs. Everything is described there.
@rkotcherr Thank you for solving my problem
I am unable to get the sample app to work.
What I did
I downloaded the django-tenant-schemas repository, created a virtualenv in the
/examples/tenant_tutorial
directory with-p python3
and the following requirements.txt:I then went to
tenant_tutorial/settings.py
and set DATABASES.default to my local postgresql endpoint and database name.I was able to successfully run
python manage.py migrate_schemas --shared
as described in the documentation, and the following tables were created:I then went to the
customers_client
table and created the following clients:I then ran
./manage.py runserver
and was able to visit the webapp successfully.The Problem
I am never able to switch tenants. I always see "Current Tenant: None".
One thing I noticed is that I cannot see any print statements that I put in the middleware. I don't know a whole lot about Django yet, so I thought maybe this would be more obvious to somebody else.
I thought it would be appropriate to post here in case there's an update that needs to be made to the example. But most likely it's something I'm not doing quite right, but I'm out of ideas for the moment.