mik3y / django-db-multitenant Goto Github PK
View Code? Open in Web Editor NEWA simple multi-tenancy solution for Django apps.
License: Other
A simple multi-tenancy solution for Django apps.
License: Other
Hi,
At the moment TENANT_DATABASE_NAME=example.com ./manage.py runserver doesn't work because django loads the settings after it tries to connect to mysql. This can be fixed by adding
python
from db_multitenant.utils import update_database_from_env
if not dbname:
utils.update_database_from_env(super(DatabaseWrapper, self).get_connection_params())
dbname = self.threadlocal.get_dbname()
to _cursor() between line 51 and 52 in db/backends/mysql/base.py.
SQLite 3 does not support multi schemas/databases. Implementing a SQLite 3 database backend would require a novel approach.
Unfortunately, solely executing "USE" through the database cursor would not work for SQLite 3.
At first thought, I planned to prepend the tenant's name to DATABASES["default"]["NAME"]
.
Hi,
I am a little confused at the setup for this. It looks like your multi-tenant is going to work for what I want. But, I don't see where to setup the USER, PASSWORD and HOST for the database. Could you advise?
My settings.py is something like this:
DATABASES = {
'default': {
'ENGINE': 'db_multitenant.db.backends.mysql',
'NAME': 'test',
'USER': '****',
'PASSWORD': '****',
'HOST': '/Applications/MAMP/tmp/mysql/mysql.sock',
'PORT': '3306',
}
}
But its giving me the error
"OperationalError at /admin/
(1049, "Unknown database 'tenant-localhost'")"
I guess it should search for the "test" database, but its not.
Can you guys please guide me to right direction.Thanks in advance.
I am testing this library for a small project. I am using postgres db.
The problem I am facing is that I am unable to create super user from shell. I have specified database in the shell eg.
python manage.py createsuperuser --database mydb
and then i get the error
django.core.exceptions.ImproperlyConfigured: Tenant name not set at cursor create time.
Since there isn't any comprehensive documentation available for it, I wanted to ask if there is a way to work this out?
UPDATE: I even tried
TENANT_NAME=mydb ./manage.my migrate --database=mydb
where mydb is the name of tenant and also for the database
I am getting
Keys must be str()'s, not unicode. Convert your unicode strings using mystring.encode(charset)!
when using cache.helper.multitenant_key_func
using key.encode('ascii', 'ignore')
or django.utils.encoding.force_text
on the returned key fixes it.
Thank you for this work ... I'm testing in an app at the moment with good success so far.
QUESTION: Is it possible to do multi schema updates at the same time for POSTGRESQL... e.g. TENANT_NAME=*?
How many changes we have to do to allow this app to work with PostgreSQL? How complicated it could be?
I'm interested in using it with PostgreSQL because it is the only app that I found that implements the Isolated Approach.
Hi @mik3y,
The requirement I'm trying to implement tells me that the tenant is known after a user is logged in, it means, the user table is shared or public and contains the tenant's name, and then we can have a different database per tenant.
Is this currently possible with your library?. Please give me some hints about implementing it if possible.
Thanks in advance.
I don't actively use this project any more, but looks like it has a modest user base, which is great.
@stephane would you like to be added as maintainer?
I have a working installation of django-db-multitenant, its perfect for my use case thanks.
However, I cannot get the management commands to work, such as:
TENANT_DATABASE_NAME=example.com ./manage.py migrate
How do I call such a command from a venv in Windows 10 Python installation?
Also, do you have a solution for looping the migration commands over multiple databases in MySQL (like database names app_bqt, app_cre, app_trb etc) ?
The README states the project is under Apache 2 license but some files refer to 3-Clause BSD licence (such as utils.py).
Which is the license of the project?
TENANT_NAME=company ./manage.py migrate Erro "Is not recognized as an internal or external command
and I am using windows 10
Hi,
Good work, I like this module and it's working so far in my tests. But I found out some issues.
There's a problem using this module. If you use South to migrate your tables, this stop working with the error "Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x108ec2450>>"
My guess, it's that it's not supported for South.
Also, when using the 'ENGINE': 'db_multitenant.db.backends.mysql', commands like "python manage.py syncdb" or "python manage.py sql" return the error: "NameError: global name 'ImproperlyConfigured' is not defined"
How did you manage to solve your table migrations and creations?
Best Regards
I followed all the steps that you mentioned in your docs but I always get the same error "dbname not set at cursor create time" when I run the project. I even sent a static database name inside the mapper just to try it and it returned the same error. It looks like it cannot initiate with the default database that I already added inside the settings. Any suggestions?
I use MySQL and have this error at django runserver.
If You have the same problem.
Just try to upgrade mysqlclient version.
If i save my mapper in directory [app_config]\tenants\mapper - class Mapper
and in settings
MULTITENANT_MAPPER_CLASS = '[app_config].tenants.mapper.Mapper'
I will have an error
"Could not import mapper:..." - utils.py line 71
may be you need to replace try constuction?
try:
module_path, member_name = name.rsplit(".", 1)
module = import_module(module_path)
cls = getattr(module, member_name)
to
try:
from pydoc import locate
cls = locate(name)
Hi,
In readme we red that "Isolated approach: Separate database per tenant." is just for MySQL ?,
We need this to work with PostgreSQL (Database per Tenant) not schema. is this possible with PostgreSQL ????
Thank you
I have a few minor changes to apply to the documentation and some tests to pass before publishing a new release. In the meantime, could you give me the right to push a new release on Pypi or do you want to publish them?
My pypi account is stephane
.
I did not realize that this did not (yet) support Postgres until I saw an issue requesting such support
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.