From 307acc745a4e655c35db96f96ceb4b87597dee49 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 13 May 2015 08:19:51 -0400 Subject: Fixed #24630 -- Clarified docs about RunPython transactions. Thanks Markus Holtermann for review. --- docs/ref/migration-operations.txt | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'docs/ref') diff --git a/docs/ref/migration-operations.txt b/docs/ref/migration-operations.txt index 991cc6f33b..31ea32ee9d 100644 --- a/docs/ref/migration-operations.txt +++ b/docs/ref/migration-operations.txt @@ -322,11 +322,23 @@ or that you use :class:`SeparateDatabaseAndState` to add in operations that will reflect your changes to the model state - otherwise, the versioned ORM and the autodetector will stop working correctly. -By default, ``RunPython`` will run its contents inside a transaction even -on databases that do not support DDL transactions (for example, MySQL and +By default, ``RunPython`` will run its contents inside a transaction on +databases that do not support DDL transactions (for example, MySQL and Oracle). This should be safe, but may cause a crash if you attempt to use -the ``schema_editor`` provided on these backends; in this case, please -set ``atomic=False``. +the ``schema_editor`` provided on these backends; in this case, pass +``atomic=False`` to the ``RunPython`` operation. + +On databases that do support DDL transactions (SQLite and PostgreSQL), +``RunPython`` operations do not have any transactions automatically added +besides the transactions created for each migration (the ``atomic`` parameter +has no effect on these databases). Thus, on PostgreSQL, for example, you should +avoid combining schema changes and ``RunPython`` operations in the same +migration or you may hit errors like ``OperationalError: cannot ALTER TABLE +"mytable" because it has pending trigger events``. + +If you have a different database and aren't sure if it supports DDL +transactions, check the ``django.db.connection.features.can_rollback_ddl`` +attribute. .. warning:: -- cgit v1.3