diff --git a/docs/ref/migration-operations.txt b/docs/ref/migration-operations.txt
index 8dbebcc..2a8dbfd 100644
a
|
b
|
queries and parameters in the same way as :ref:`cursor.execute()
|
224 | 224 | If you want to include literal percent signs in the query, you have to double |
225 | 225 | them if you are passing parameters. |
226 | 226 | |
| 227 | The ``reverse_sql`` statement is executed when the migration is reversed. So you can |
| 228 | reverse the changes done in the first statement:: |
| 229 | |
| 230 | migrations.RunSQL( |
| 231 | ["INSERT INTO musician (name) VALUES (%s);", ['Reinhardt']], |
| 232 | ["DELETE FROM musician where name=%s;", ['Reinhardt']] |
| 233 | ) |
| 234 | |
227 | 235 | The ``state_operations`` argument is so you can supply operations that are |
228 | 236 | equivalent to the SQL in terms of project state; for example, if you are |
229 | 237 | manually creating a column, you should pass in a list containing an ``AddField`` |
… |
… |
match the operation's place in the project history, and the second is an
|
265 | 273 | instance of :class:`SchemaEditor |
266 | 274 | <django.db.backends.base.schema.BaseDatabaseSchemaEditor>`. |
267 | 275 | |
| 276 | The ``reverse_code`` argument is called when running migrations backward. |
| 277 | This callable is used so that the migration is reversible by undoing |
| 278 | what is being done in the ``code`` argument. |
| 279 | |
268 | 280 | The optional ``hints`` argument will be passed as ``**hints`` to the |
269 | 281 | :meth:`allow_migrate` method of database routers to assist them in making a |
270 | 282 | routing decision. See :ref:`topics-db-multi-db-hints` for more details on |
… |
… |
model::
|
294 | 306 | Country(name="France", code="fr"), |
295 | 307 | ]) |
296 | 308 | |
| 309 | def backwards_func(apps, schema_editor): |
| 310 | # forwards_func creates two Country instance, |
| 311 | # so backwards_func should delete them |
| 312 | Country = apps.get_model("myapp", "Country") |
| 313 | db_alias = schema_editor.connection.alias |
| 314 | Country.objects.using(db_alias).filter(name="USA", code="us").delete() |
| 315 | Country.objects.using(db_alias).filter(name="France", code="fr").delete() |
| 316 | |
297 | 317 | class Migration(migrations.Migration): |
298 | 318 | |
299 | 319 | dependencies = [] |
… |
… |
model::
|
301 | 321 | operations = [ |
302 | 322 | migrations.RunPython( |
303 | 323 | forwards_func, |
| 324 | backwards_func |
304 | 325 | ), |
305 | 326 | ] |
306 | 327 | |