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

Migrating with South

Migrating with South

A talk I gave at DJUGL #2

Andrew Godwin

January 19, 2009
Tweet

More Decks by Andrew Godwin

Other Decks in Programming

Transcript

  1. A�migration! south Migrating�with from south.db import db from core.models import

    * cl ass Migration: def forwards(self): db.add_column("core_nation", "slug", models.SlugField(unique=True, default="test") ) def backwards(self): db.add_column("core_nation", "slug")
  2. How�is�migration�formed? south Migrating�with ./manage.py startmigration core test_migration The�South�command App�name Migration�name

    ./manage.py startmigration core \ test_migration Blank�migration: Add�everything�(initial;�replaces�the�syncdb): --initial ./manage.py startmigration core \ test_migration Add�a�new�field: --add-field Picture.slug These�all�make�a�file�like�c ore/migrations/0002_test_migration.py.
  3. Installation south Migrating�with Put�South�somewhere�on�the�Python�path svn co http://.../trun k/south/ easy_install South

    or Add�it�to�INSTALLED_APPS INSTALLED_APPS = [ ... , "south" ] Run�syncdb�(South�uses�a�table�to�track�applied�migrations) ./manage.py syncdb That's�it.�Start�migrating. (We�have�docs�on�things�like�converting�existing�apps)
  4. south Migrating�with epic�fail fail win M ySQL Postgres SQLite SQL�Server

    Highly�scientific�graph No�DDL�Transactions No�Column�Alters Awesome. Ugh.
  5. south Migrating�with # M ock M odel s User =

    db.mock_model(model_name='User', db_table='auth_user', db_tablespace='', pk_field_name='id', pk_field_type=models.AutoField) # M odel ' User Pr of i l e' db.create_table('core_userprofile', ( ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), ('user', models.OneToOneField(User, related_name="profile")), )) API�Example