mik3y / django-db-multitenant

A simple multi-tenancy solution for Django apps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SyncDB and South module stop working

hugocore opened this issue · comments

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

Thanks for the feedback!

There's a problem using this module. If you use South to migrate your tables, this stop working...

Can you try adding the following to your settings and see if it helps?

SOUTH_DATABASE_ADAPTERS['default'] = 'south.db.mysql'

"NameError: global name 'ImproperlyConfigured' is not defined"

Oops, this is now fixed.

Thanks for the response!

  • South now works with multi databases!
    As it turned out, adding the following code to the "settings.py", enabled South:
    SOUTH_DATABASE_ADAPTERS = {
    'default': 'south.db.mysql'
    }
  • To be able to run management commands, I followed your guide and added the following to the end of "settings.py":
    from db_multitenant import utils
    ....
    utils.update_database_from_env(DATABASES['default'])
    utils.update_cache_from_env(CACHES['default'])
  • Just be sure to set the environment variable correctly, otherwise you'll get the error ImproperlyConfigured('dbname not set at cursor create time'). I used "export TENANT_DATABASE_NAME=dbname" and "launchctl setenv TENANT_DATABASE_NAME db_name" to finally get the variable set.
  • For my own use, I also added the following to "utils.py" so I can see to which database I'm running the command:
    print >> sys.stderr, "DB: %s\n" % dbname

Ps. I think that these last modifications are not in the PIP repository, because even uninstalling and installing the package didn't download these modifications. Unless it's some problem with my pip cache.