你可以寫任何東西作爲遷移。這纔是重點!
啓動並運行South
後,請輸入python manage.py schemamigration myapp --empty my_custom_migration
以創建可自定義的空白遷移。
在myapp/migrations/
中打開XXXX_my_custom_migration.py
文件,然後在forwards
方法中鍵入您的自定義SQL遷移。例如,你可以使用db.execute
遷移可能是這個樣子:
class Migration(SchemaMigration):
def forwards(self, orm):
db.execute("CREATE FULLTEXT INDEX foo ON bar (foobar)")
print "Just created a fulltext index..."
print "And calculated {answer}".format(answer=40+2)
def backwards(self, orm):
raise RuntimeError("Cannot reverse this migration.")
# or what have you
$ python manage.py migrate myapp XXXX # or just python manage.py migrate.
"Just created fulltext index...."
"And calculated 42"