你可以写任何东西作为迁移。这才是重点!
启动并运行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"