|Version 13 (modified by andrew, 6 years ago) (diff)|
South comes with a simplistic database abstraction layer that sits above DBAPI, which provides a common connection cursor and sql-slinging interface, and below Django's database API, which deals with high-level data.
south.db (as this layer is known) allows you to create, modify and delete tables, columns and other database items (like indexes) in a database-agnostic way, so you can just reuse your migrations if you switch database rather than having to rewrite all the SQL.
All operations are methods on the south.db.db object; the usual import to have is
from south.db import db
This line will have automatically been added to your migrations if you created them using startmigration.
For detailed documentation on each API method, there are links to them from the Documentation page.
- db.create_table(table_name, fields)
- db.delete_table(table_name, cascade=True)
- db.rename_table(table_name, new_table_name)
- db.add_column(table_name, field_name, field, keep_default=True)
- db.delete_column(table_name, column_name)
- db.alter_column(table_name, column_name, field, explicit_name=True)
- db.rename_column(table_name, column_name, new_column_name)
- db.create_index(table_name, column_names, unique=False, db_tablespace="")
- db.delete_index(table_name, column_names, db_tablespace="")
- db.send_create_signal(app_label, model_names)