Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Database Migrations, South, And You
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Andrew Godwin
September 08, 2009
Programming
200
0
Share
Database Migrations, South, And You
A talk I gave at DjangoCon US 2009
Andrew Godwin
September 08, 2009
More Decks by Andrew Godwin
See All by Andrew Godwin
Reconciling Everything
andrewgodwin
1
380
Django Through The Years
andrewgodwin
0
300
Writing Maintainable Software At Scale
andrewgodwin
0
510
A Newcomer's Guide To Airflow's Architecture
andrewgodwin
0
400
Async, Python, and the Future
andrewgodwin
2
720
How To Break Django: With Async
andrewgodwin
1
790
Taking Django's ORM Async
andrewgodwin
0
790
The Long Road To Asynchrony
andrewgodwin
0
750
The Scientist & The Engineer
andrewgodwin
1
830
Other Decks in Programming
See All in Programming
我々はなぜ「層」を分けるのか〜「関心の分離」と「抽象化」で手に入れる変更に強いシンプルな設計〜 #phperkaigi / PHPerKaigi 2026
shogogg
2
910
CDK Deployのための ”反響定位”
watany
4
690
2026-03-27 #terminalnight 変数展開とコマンド展開でターミナル作業をスマートにする方法
masasuzu
0
320
Kubernetes上でAgentを動かすための最新動向と押さえるべき概念まとめ
sotamaki0421
3
480
forteeの改修から振り返るPHPerKaigi 2026
muno92
PRO
3
270
Laravel Nightwatchの裏側 - Laravel公式Observabilityツールを支える設計と実装
avosalmon
1
330
アーキテクチャモダナイゼーションとは何か
nwiizo
17
4.8k
ローカルで稼働するAI エージェントを超えて / beyond-local-ai-agents
gawa
3
270
車輪の再発明をしよう!PHP で実装して学ぶ、Web サーバーの仕組みと HTTP の正体
h1r0
3
520
Codex CLIのSubagentsによる並列API実装 / Parallel API Implementation with Codex CLI Subagents
takatty
2
890
ネイティブアプリとWebフロントエンドのAPI通信ラッパーにおける共通化の勘所
suguruooki
0
260
Codex CLI でつくる、Issue から merge までの開発フロー
amata1219
0
340
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.3k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
140
Building Adaptive Systems
keathley
44
3k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
720
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
240
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
290
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
190
Deep Space Network (abreviated)
tonyrice
0
110
Transcript
database�migrations, southand�you Andrew�Godwin
[email protected]
What�are�migrations? http://www.flickr.com/photos/moonjazz/1216783552/
They're�NOT�moving�data�from� one�database�to�another. http://www.flickr.com/photos/shindotv/3835365427/
Better�name:�Schema�Evolution. http://www.flickr.com/photos/fmc550uz/3562899067/
Django�has�nothing�built-in.
+ + =
+ + = Migration�1:�Creates�table�A Migration�2:�Creates�table�B Migration�3:�Adds�field�to�A, ������������������������creates�t able�C Apply�each�in�order,�get�current�schema
One�set�of�migrations�per�app. http://www.flickr.com/photos/dan_h/2517103627/
Apps�aren't�really�independent. http://www.flickr.com/photos/johnbullas/3301805150/
None
None
Is�your�app�fresh,�or�old? http://www.flickr.com/photos/matthewfch/536763437/
Fresh? -�Populate�appname/models.py -�Make�your�initial�migration: ./manage.py startmigration appname --initial -�Apply�that�migration ./manage.py migrate
appname
Already�syncdb'd? -�Locally,�run: ./manage.py convert_to_south appname -�Commit,�and�then�on�others�do: ./manage.py migrate --fake appname
0001 (see:�south.aeracode.org/wiki/ConvertingAnApp)
Migrations�are�flexible. http://www.flickr.com/photos/dunechaser/2630434670/
Autodetection ./manage.py startmigration \ --auto appname added_some_column Use�the�autodetector Name�of�the�app Suffix�of�the�new�migration
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')
We�'freeze'�model�definitions. http://www.flickr.com/photos/stuckincustoms/3410783929/
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']" } ), ... }
We�migrate�data,�too. http://www.flickr.com/photos/ian-s/2152798588/
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()
Roll�your�own�migrations. http://www.flickr.com/photos/thomashawk/93819794/
Unit�test�integration,�if�you�want http://www.flickr.com/photos/cobalt/409924867/
The�Future�World�Of�Tomorrow http://www.flickr.com/photos/stuckincustoms/211566219/
Thanks�for�listening. http://www.flickr.com/photos/sovietuk/378834721/ http://south.aeracode.org Andrew�Godwin
[email protected]
Thanks�for�listening. http://www.flickr.com/photos/sovietuk/378834721/ http://south.aeracode.org Andrew�Godwin
[email protected]
@andrewgodwin