<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Eric Florenzano's Blog - Latest Comments in Easy Multi-Database Support for Django</title><link>http://ericflorenzanosblog.disqus.com/</link><description>Eric Florenzano's Blog</description><atom:link href="https://ericflorenzanosblog.disqus.com/easy_multi_database_support_for_django/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 17 Jul 2009 10:18:00 -0000</lastBuildDate><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13325718</link><description>&lt;p&gt;&lt;/p&gt;&lt;p&gt;that's a great post, thank you!&lt;br&gt; &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">radyo dinle</dc:creator><pubDate>Fri, 17 Jul 2009 10:18:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13325717</link><description>&lt;p&gt;&lt;/p&gt;&lt;p&gt;that's a great post, thank you!&lt;br&gt; &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">sohbet</dc:creator><pubDate>Fri, 17 Jul 2009 10:18:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13325557</link><description>&lt;p&gt;Of course, different classes must be created for different database:&lt;/p&gt;&lt;p&gt;MultiDBManager_primary = type('MultiDBManager_primary', (MultiDBManager,), {'database':'primary'})&lt;/p&gt;&lt;p&gt;MultiDBManager_secondary = type('MultiDBManager_secondary', (MultiDBManager,), {'database':'secondary'})&lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">DNKorolkov</dc:creator><pubDate>Thu, 16 Jul 2009 23:15:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13325556</link><description>&lt;p&gt;Problem with create of MultiDBManager for ManyToManyField.&lt;/p&gt;&lt;p&gt;MultiDBManager.__init__ require 'database' parameter.&lt;br&gt;Its cause error with call "super(ManyRelatedManager, self).__init__()" in ManyRelatedManager.__init__&lt;br&gt;(function create_many_related_manager of django/db/models/fields/&lt;a href="http://related.py" rel="nofollow noopener" target="_blank" title="related.py"&gt;related.py&lt;/a&gt;).&lt;/p&gt;&lt;p&gt;Proposed solution:&lt;br&gt;Set 'database' as class attribute instead __init__ argument:&lt;/p&gt;&lt;p&gt;MultiDBManager = type('MultiDBManager', (MultiDBManager,), {'database':'db_name'})&lt;/p&gt;&lt;p&gt;P.S. Excuse my English, please ;-).&lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">DNKorolkov</dc:creator><pubDate>Thu, 16 Jul 2009 23:05:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13325514</link><description>&lt;p&gt;It is throwing an error when i changed my &lt;a href="http://settings.py" rel="nofollow noopener" target="_blank" title="settings.py"&gt;settings.py&lt;/a&gt;&lt;/p&gt;&lt;p&gt;the error is:&lt;/p&gt;&lt;p&gt;could not connect to server: No such file or directory&lt;br&gt;	Is the server running locally and accepting&lt;br&gt;	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?&lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">ha22109</dc:creator><pubDate>Thu, 16 Jul 2009 19:02:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13325171</link><description>&lt;p&gt;If anyone else was stuck with the multiple mysql connections issue, I *think* I have got around it (with help from other people's ideas!):&lt;/p&gt;&lt;p&gt;&lt;a href="http://groups.google.com/group/django-users/msg/d1d7e0af565cc444?" rel="nofollow noopener" target="_blank" title="http://groups.google.com/group/django-users/msg/d1d7e0af565cc444?"&gt;http://groups.google.com/gr...&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Emily</dc:creator><pubDate>Tue, 14 Jul 2009 05:08:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13324843</link><description>&lt;p&gt;Thanks for this.&lt;/p&gt;&lt;p&gt;I am having issues with multiple connections not being closed though (has been mentioned above).&lt;/p&gt;&lt;p&gt;Has anyone got a work around for this?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Emily</dc:creator><pubDate>Mon, 06 Jul 2009 21:50:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323826</link><description>&lt;p&gt;I spent many years trying to create multiple databases with MySQL. I finally got to the simple solution (for the several transactional based database applications we wrote) of preceding the table name with the database name (eg. db1.person inner join db2.organisation).&lt;/p&gt;&lt;p&gt;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?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Nigel Cohen</dc:creator><pubDate>Tue, 02 Jun 2009 02:00:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323757</link><description>&lt;p&gt;Based on rules written in Lua, you could direct queries using the primary / secondary model you have in this post, or split reads to a Slave instance and writes to a Master.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">ben 10 oyunları</dc:creator><pubDate>Sun, 24 May 2009 21:06:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323695</link><description>&lt;p&gt;For those on SVN django: as of 10059 you will need to add :&lt;/p&gt;&lt;p&gt;use_for_related_fields = True&lt;/p&gt;&lt;p&gt;to the subclassed  manager  for this to work.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Richard McMillan</dc:creator><pubDate>Mon, 11 May 2009 06:25:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323631</link><description>&lt;p&gt;Hi Nice articles, i have not tried but may be in future will really help.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Praveen</dc:creator><pubDate>Thu, 02 Apr 2009 18:23:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323627</link><description>&lt;p&gt;FYI:&lt;/p&gt;&lt;p&gt;  Using _default_manager in a model causes many idle MySQL connections. (Django 1.0)&lt;/p&gt;&lt;p&gt;&lt;a href="http://groups.google.com/group/django-users/browse_thread/thread/6ed797f6b00dca90" rel="nofollow noopener" target="_blank" title="http://groups.google.com/group/django-users/browse_thread/thread/6ed797f6b00dca90"&gt;http://groups.google.com/group/django-users/browse_thread/thread/6ed797f6b00dca90&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">J</dc:creator><pubDate>Mon, 30 Mar 2009 22:19:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323583</link><description>&lt;p&gt;I may have solved my own problem. In your example I changed the line &lt;br&gt;"_default_manager = MultiDBManagr('secondary')" to &lt;br&gt;"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.&lt;/p&gt;&lt;p&gt;Thanks for the great tutorial, Eric!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jordan Keyes</dc:creator><pubDate>Mon, 16 Mar 2009 07:15:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323582</link><description>&lt;p&gt;I have tried this both with Django 1.0.2 and with the latest SVN version (from 3/16/09) using the settings Adrian mentioned. Both ways, the multi_syncdb shown seems to be doing a two-way sync (putting all of my models in both databases). &lt;br&gt;If I run "python &lt;a href="http://manage.py" rel="nofollow noopener" target="_blank" title="manage.py"&gt;manage.py&lt;/a&gt; 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.&lt;br&gt;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?&lt;/p&gt;&lt;p&gt;For reference, I am using Python 2.5, Django from SVN, django-mssql from SVN for SQL 2005 connection. &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jordan Keyes</dc:creator><pubDate>Mon, 16 Mar 2009 04:02:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323576</link><description>&lt;p&gt;As of &lt;a href="http://code.djangoproject.com/changeset/10026" rel="nofollow noopener" target="_blank" title="http://code.djangoproject.com/changeset/10026"&gt;http://code.djangoproject.c...&lt;/a&gt;, this code snippet will no longer work. Fortunately, it's a lot easier/cleaner now. The get_db_wrapper() method can be rewritten something like this (untested):&lt;/p&gt;&lt;p&gt;def get_db_wrapper(self):&lt;br&gt;    database = settings.DATABASES[self.database]&lt;br&gt;    backend = __import__('django.db.backends.' + database['DATABASE_ENGINE']&lt;br&gt;        + ".base", {}, {}, ['base'])&lt;br&gt;    return backend.DatabaseWrapper(database)&lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Joseph Kocherhans</dc:creator><pubDate>Tue, 10 Mar 2009 17:56:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323514</link><description>&lt;p&gt;good reading!!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">re</dc:creator><pubDate>Fri, 05 Dec 2008 19:04:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323455</link><description>&lt;p&gt;Forenkey has error&lt;/p&gt;&lt;p&gt;how fix it ?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jfy3d</dc:creator><pubDate>Thu, 27 Nov 2008 00:45:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323398</link><description>&lt;p&gt;Not thread-savvy. It would be cool to pass the settings as a dictionary and not changing the global settings object.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">guille_</dc:creator><pubDate>Sat, 22 Nov 2008 00:48:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323396</link><description>&lt;p&gt;fixed the other problem. type on database name on my part.&lt;/p&gt;&lt;p&gt;looking at a new problem. when i try to access the Link objects i get "type object 'Link" has no attribute 'objects'&lt;/p&gt;&lt;p&gt;l = Link.objects.all()&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">enoch</dc:creator><pubDate>Fri, 21 Nov 2008 06:38:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323385</link><description>&lt;p&gt;looks great. any troubleshooting help. i setup the same stuff and keep getting a problem in the admin views for the Link objects that "Something's wrong with your database installation. Make sure the appropriate database tables have been created, and make sure the database is readable by the appropriate user."&lt;/p&gt;&lt;p&gt;what's odd is, that's on listing, but on "add new" link, it brings up a from fine to add a new link....&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">enoch</dc:creator><pubDate>Thu, 20 Nov 2008 16:53:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323373</link><description>&lt;p&gt;I'm getting deadlocks when trying to update on mysql/innodb&lt;br&gt;&lt;a href="http://dpaste.com/92408/" rel="nofollow noopener" target="_blank" title="http://dpaste.com/92408/"&gt;http://dpaste.com/92408/&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Lis</dc:creator><pubDate>Wed, 19 Nov 2008 21:28:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323348</link><description>&lt;p&gt;That's pretty much how we did things :D Thanks to Malcolm for adding the hooks in Django 1.0 that allow for multiple databases!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Leah Culver</dc:creator><pubDate>Sun, 16 Nov 2008 04:00:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323345</link><description>&lt;p&gt;Nice post.  If you're using MySQL, you could use MySQL Proxy, which will accept connections from your Django application server and inspect the queries.  Based on rules written in Lua, you could direct queries using the primary / secondary model you have in this post, or split reads to a Slave instance and writes to a Master.  &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jijnes Patel</dc:creator><pubDate>Sat, 15 Nov 2008 01:48:00 -0000</pubDate></item><item><title>Re: Easy Multi-Database Support for Django</title><link>http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/#comment-13323343</link><description>&lt;p&gt;Great post! I don't need sharding for any of my projects. But now I can see how to implement it if needed.&lt;/p&gt;&lt;p&gt;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;&lt;/p&gt;&lt;p&gt;class MyClass(models.Model):&lt;br&gt;    database = 'secondary'&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Atamert Ölçgen</dc:creator><pubDate>Fri, 14 Nov 2008 22:22:00 -0000</pubDate></item></channel></rss>