summaryrefslogtreecommitdiff
path: root/docs/ref/schema-editor.txt
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-04-27 15:05:25 -0400
committerTim Graham <timograham@gmail.com>2014-04-27 15:05:41 -0400
commitab8d8e00c9d34a48a640434f454d98c02cfaeb54 (patch)
treea83aea5364a71a9d830197ae0f3a0b571f46aff5 /docs/ref/schema-editor.txt
parent8905fcbda6854b5b7fdd8a1ee3277f8f1039e114 (diff)
Improved formatting and links of migration docs.
Diffstat (limited to 'docs/ref/schema-editor.txt')
-rw-r--r--docs/ref/schema-editor.txt92
1 files changed, 35 insertions, 57 deletions
diff --git a/docs/ref/schema-editor.txt b/docs/ref/schema-editor.txt
index aeebfbc62a..e4d3fa01c0 100644
--- a/docs/ref/schema-editor.txt
+++ b/docs/ref/schema-editor.txt
@@ -1,6 +1,10 @@
-============
-SchemaEditor
-============
+================
+``SchemaEditor``
+================
+
+.. module:: django.db.backends.schema
+
+.. class:: BaseDatabaseSchemaEditor
Django's migration system is split into two parts; the logic for calculating
and storing what operations should be run (``django.db.migrations``), and the
@@ -27,10 +31,10 @@ of change are not possible on all databases - for example, MyISAM does not
support foreign key constraints.
If you are writing or maintaining a third-party database backend for Django,
-you will need to provide a SchemaEditor implementation in order to work with
+you will need to provide a ``SchemaEditor`` implementation in order to work with
1.7's migration functionality - however, as long as your database is relatively
standard in its use of SQL and relational design, you should be able to
-subclass one of the built-in Django SchemaEditor classes and just tweak the
+subclass one of the built-in Django ``SchemaEditor`` classes and just tweak the
syntax a little. Also note that there are a few new database features that
migrations will look for: ``can_rollback_ddl`` and
``supports_combined_alters`` are the most important.
@@ -41,9 +45,7 @@ Methods
execute
-------
-::
-
- execute(sql, params=[])
+.. method:: BaseDatabaseSchemaEditor.execute(sql, params=[])
Executes the SQL statement passed in, with parameters if supplied. This
is a simple wrapper around the normal database cursors that allows
@@ -52,92 +54,71 @@ capture of the SQL to a ``.sql`` file if the user wishes.
create_model
------------
-::
-
- create_model(model)
+.. method:: BaseDatabaseSchemaEditor.create_model(model)
Creates a new table in the database for the provided model, along with any
unique constraints or indexes it requires.
-
delete_model
------------
-::
-
- delete_model(model)
+.. method:: BaseDatabaseSchemaEditor.delete_model(model)
Drops the model's table in the database along with any unique constraints
or indexes it has.
-
alter_unique_together
---------------------
-::
-
- alter_unique_together(model, old_unique_together, new_unique_together)
-
-Changes a model's unique_together value; this will add or remove unique
-constraints from the model's table until they match the new value.
+.. method:: BaseDatabaseSchemaEditor.alter_unique_together(model, old_unique_together, new_unique_together)
+Changes a model's :attr:`~django.db.models.Options.unique_together` value; this
+will add or remove unique constraints from the model's table until they match
+the new value.
alter_index_together
--------------------
-::
-
- alter_index_together(model, old_index_together, new_index_together)
-
-Changes a model's index_together value; this will add or remove indexes
-from the model's table until they match the new value.
+.. method:: BaseDatabaseSchemaEditor.alter_index_together(model, old_index_together, new_index_together)
+Changes a model's :attr:`~django.db.models.Options.index_together` value; this
+will add or remove indexes from the model's table until they match the new
+value.
alter_db_table
--------------
-::
-
- alter_db_table(model, old_db_table, new_db_table)
+.. method:: BaseDatabaseSchemaEditor.alter_db_table(model, old_db_table, new_db_table)
Renames the model's table from ``old_db_table`` to ``new_db_table``.
-
alter_db_tablespace
-------------------
-::
-
- alter_db_tablespace(model, old_db_tablespace, new_db_tablespace)
+.. method:: BaseDatabaseSchemaEditor.alter_db_tablespace(model, old_db_tablespace, new_db_tablespace)
Moves the model's table from one tablespace to another.
-
add_field
---------
-::
-
- add_field(model, field)
+.. method:: BaseDatabaseSchemaEditor.add_field(model, field)
Adds a column (or sometimes multiple) to the model's table to represent the
field. This will also add indexes or a unique constraint
if the field has ``db_index=True`` or ``unique=True``.
-If the field is a ManyToManyField without a value for ``through``, instead of
-creating a column, it will make a table to represent the relationship. If
+If the field is a ``ManyToManyField`` without a value for ``through``, instead
+of creating a column, it will make a table to represent the relationship. If
``through`` is provided, it is a no-op.
If the field is a ``ForeignKey``, this will also add the foreign key
constraint to the column.
-
remove_field
------------
-::
-
- remove_field(model, field)
+.. method:: BaseDatabaseSchemaEditor.remove_field(model, field)
Removes the column(s) representing the field from the model's table, along
with any unique constraints, foreign key constraints, or indexes caused by
@@ -147,25 +128,22 @@ If the field is a ManyToManyField without a value for ``through``, it will
remove the table created to track the relationship. If
``through`` is provided, it is a no-op.
-
alter_field
------------
-::
-
- alter_field(model, old_field, new_field, strict=False)
+.. method:: BaseDatabaseSchemaEditor.alter_field(model, old_field, new_field, strict=False)
This transforms the field on the model from the old field to the new one. This
-includes changing the name of the column (the ``db_column`` attribute),
-changing the type of the field (if the field class changes), changing
-the ``NULL`` status of the field, adding or removing field-only unique
-constraints and indexes, changing primary key, and changing the destination
-of ForeignKey constraints.
+includes changing the name of the column (the
+:attr:`~django.db.models.Field.db_column` attribute), changing the type of the
+field (if the field class changes), changing the ``NULL`` status of the field,
+adding or removing field-only unique constraints and indexes, changing primary
+key, and changing the destination of ``ForeignKey`` constraints.
The most common transformation this cannot do is transforming a
-ManyToManyField into a normal Field or vice-versa; Django cannot do this
-without losing data, and so it will refuse to do it. Instead, ``remove_field``
-and ``add_field`` should be called separately.
+``ManyToManyField`` into a normal Field or vice-versa; Django cannot do this
+without losing data, and so it will refuse to do it. Instead,
+:meth:`.remove_field` and :meth:`.add_field` should be called separately.
If the database has the ``supports_combined_alters``, Django will try and
do as many of these in a single database call as possible; otherwise, it will