-
Website
http://www.eflorenzano.com/ -
Original page
http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
traviscooper
1 comment · 2 points
-
pppoll37
7 comments · 1 points
-
linhanyi
2 comments · 1 points
-
dobrych
2 comments · 3 points
-
bosveld
1 comment · 1 points
-
-
Popular Threads
I think it would look much cooler if the database name was a class variable. But I guess it would require patching the models.Manager. Such as;
class MyClass(models.Model):
database = 'secondary'
See http://dpaste.de/605/ for an example.
http://dpaste.com/92408/
what's odd is, that's on listing, but on "add new" link, it brings up a from fine to add a new link....
looking at a new problem. when i try to access the Link objects i get "type object 'Link" has no attribute 'objects'
l = Link.objects.all()
how fix it ?
def get_db_wrapper(self):
database = settings.DATABASES[self.database]
backend = __import__('django.db.backends.' + database['DATABASE_ENGINE']
+ ".base", {}, {}, ['base'])
return backend.DatabaseWrapper(database)
If I run "python manage.py shell" I can manually create items in the tables, but it doesn't appear to be using the _default_manager to decide where to put the items, just going for the secondary database.
Also, it seems the manager is working, but only partially. Any time I try to access the objects in the tables, I get errors like "type object 'TwebprPress' has no attribute 'objects'" (for TwebprPress.objects.all()) Have I done something wrong?
For reference, I am using Python 2.5, Django from SVN, django-mssql from SVN for SQL 2005 connection.
"_default_manager = MultiDBManagr('secondary')" to
"objects = MultiDBManager('secondary')" on each model (changing secondary to the appropriate DB name from the Dict.) and things seem to be working appropriately now. The multi_syncdb is still a little borked, but I can do without that.
Thanks for the great tutorial, Eric!
Using _default_manager in a model causes many idle MySQL connections. (Django 1.0)
http://groups.google.com/group/django-users/browse_thread/thread/6ed797f6b00dca90
use_for_related_fields = True
to the subclassed manager for this to work.
Could this essential (for large apps) multi-database functionality not be achieved quite simply by setting up a variable in the Model object allowing a database name to be updated - which the MySQL generating code looks at when generating the MySQL code?
I am having issues with multiple connections not being closed though (has been mentioned above).
Has anyone got a work around for this?
http://groups.google.com/group/django-users/msg...
the error is:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
MultiDBManager.__init__ require 'database' parameter.
Its cause error with call "super(ManyRelatedManager, self).__init__()" in ManyRelatedManager.__init__
(function create_many_related_manager of django/db/models/fields/related.py).
Proposed solution:
Set 'database' as class attribute instead __init__ argument:
MultiDBManager = type('MultiDBManager', (MultiDBManager,), {'database':'db_name'})
P.S. Excuse my English, please ;-).
MultiDBManager_primary = type('MultiDBManager_primary', (MultiDBManager,), {'database':'primary'})
MultiDBManager_secondary = type('MultiDBManager_secondary', (MultiDBManager,), {'database':'secondary'})