| | 71 | |
| | 72 | As 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 | |
| | 74 | If you open up the migration file it made - `southdemo/migrations/0001_initial.py` - you'll see this: |
| | 75 | |
| | 76 | {{{ |
| | 77 | #!python |
| | 78 | from south.db import db |
| | 79 | from django.db import models |
| | 80 | from southdemo.models import * |
| | 81 | |
| | 82 | class 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 | |
| | 113 | Migrations 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 | |
| | 115 | Each 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 | |
| | 117 | Most 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. |