Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Database Migrations, South, And You

Andrew Godwin
September 08, 2009

Database Migrations, South, And You

A talk I gave at DjangoCon US 2009

Andrew Godwin

September 08, 2009
Tweet

More Decks by Andrew Godwin

Other Decks in Programming

Transcript

  1. class Migration: def forwards(self, orm): # Adding field 'Adopter.lizard2' db.add_column('southdemo_adopter',

    'lizard2', orm['southdemo.adopter:lizard2']) def backwards(self, orm): # Deleting field 'Adopter.lizard2' db.delete_column('southdemo_adopter', 'lizard2_id')
  2. models = { 'southdemo.adopter' : { 'first_name': ( 'django.db.models.fields.CharField' ,

    [], {'max_length': '50'} ), 'lizard': ( 'django.db.models.fields.related.ForeignKey' , [], { 'related_name' : "'adopters'", 'to': "orm['southdemo.Lizard']" } ), ... }
  3. def forwards(self, orm): for adopter in orm.Adopter.objects.all(): try: adopter.first_name, adopter.last_name

    = \ adopter.name.split( " ", 1) except ValueError : adopter.first_name, adopter.last_name = \ adopter.name, "" adopter.save()