Database Migrations, South, And You

Database Migrations, South, And You

A talk I gave at DjangoCon US 2009

077e9a0cb34fa3eba2699240c9509717?s=128

Andrew Godwin

September 08, 2009
Tweet

Transcript

  1. 6.
  2. 10.
  3. 11.
  4. 17.

    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')
  5. 19.

    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']" } ), ... }
  6. 21.

    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()