Changes between Version 4 and Version 5 of Tutorial1


Ignore:
Timestamp:
04/03/09 13:58:15 (4 years ago)
Author:
andrew
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Tutorial1

    v4 v5  
    6969Created 0001_initial.py. 
    7070}}} 
     71 
     72As you can see, it has made our `southdemo/migrations` directory for us, as well as putting an __init__.py file in it (to mark it as a Python package - this is also required). 
     73 
     74If you open up the migration file it made - `southdemo/migrations/0001_initial.py` - you'll see this: 
     75 
     76{{{ 
     77#!python 
     78from south.db import db 
     79from django.db import models 
     80from southdemo.models import * 
     81 
     82class Migration: 
     83     
     84    def forwards(self, orm): 
     85         
     86        # Adding model 'Lizard' 
     87        db.create_table('southdemo_lizard', ( 
     88            ('age', models.IntegerField()), 
     89            ('id', models.AutoField(primary_key=True)), 
     90            ('name', models.CharField(max_length=30)), 
     91        )) 
     92        db.send_create_signal('southdemo', ['Lizard']) 
     93         
     94        # Adding model 'Adopter' 
     95        db.create_table('southdemo_adopter', ( 
     96            ('lizard', models.ForeignKey(orm.Lizard)), 
     97            ('id', models.AutoField(primary_key=True)), 
     98            ('name', models.CharField(max_length=50)), 
     99        )) 
     100        db.send_create_signal('southdemo', ['Adopter']) 
     101         
     102     
     103     
     104    def backwards(self, orm): 
     105         
     106        # Deleting model 'Lizard' 
     107        db.delete_table('southdemo_lizard') 
     108         
     109        # Deleting model 'Adopter' 
     110        db.delete_table('southdemo_adopter') 
     111}}} 
     112 
     113Migrations in South are, as you can see, just Migration classes with forwards() and backwards() methods, which get run as you go forwards or backwards over the migration respectively. 
     114 
     115Each method gets an 'orm' parameter, which contains a 'fake ORM' - it will let you access any frozen models for this migration (details on frozen models are covered in [wiki:Tutorial3 part three of the tutorial). 
     116 
     117Most of the time, you can get `startmigration` to write either all or most of a migration for you; continue to [wiki:Tutorial2 part two of the tutorial] for more about changing models.