Wednesday, November 11, 2009

django-evolution aka orm pain part 2

Finally bit the bullet and tried out a new application to help me do the changes I needed to do on the db and boy am I glad I did. django-evolution is a joy to use. It's easy to install with no strange dependencies and it did everything out of the box as described. Initially somethings did trip me up such as the django-evolution's initialization actually looks only at the models.py and does not actually bother what is really in the db, as in say the models.py you define a field that is not actually in the db during the first 'python manage.py syncdb' to create the django-evolution table, it does not actually know that and will just carry on not knowing that there are discrepancies between the models.py and the actual db.

After I figured that part out, it was easy. Just add the fields and their attributes, re-run an update script on my data and everything is done. Now my selects are much faster. Initially a 3k row db select was taking 50s and now using the caching functionality of select_related() it comes back in a blazing 4s. Ah here too initially I got tripped a bit as after putting in all the relationship I noticed that it still did not do a cache select_related until I did some digging and found that all columns defined with 'null=True' is not cached by select_related(). Looking at the actual sql generated by the Django CRM, it looks proper and very well done. I am still checking out the little nooks and crannies of the application but so far I give django-evolution the thumbs up! I am actually looking at the code to see if during the initial syncdb django-evolution can actually peer into the db to see if the definitions are actually kosher before proceeding.

3 comments:

bcat said...

Have you looked at South (http://south.aeracode.org/)? It is the de-facto standard for Django database migrations.

lowks said...

I haven't yet, but I plan to as many comments left here has suggested that. I have saved the original dump and plan to use it to do the same migration.

Dougal said...

You certainly do want to try South out.

The learning curve is a little steeper to start with but after your passed that I've found it to be a much better app.

As far as I know the original django-evolution developers almost all use south now... Kinda goes to show south is the natural choice these days. At least, most of the core django developers have moved to south.