However, if no backwards callable is specified, the respective migration
isn't reversible. And the forwards callable is required.
I propose to add a class attribute that effectively provides a no-op but
makes the code a bit more expressive:
{{{#!python
class RunPython(Operation):
# ...
noop = lambda apps, schema_editor: None
}}}
Hence the migration could look like
{{{#!python
from django.db import migrations
def forwards(apps, schema_editor):
# Do some stuff
class Migration(migrations.Migration):
operations = [
# Current way
migrations.RunPython(forwards, lambda apps, schema_editor: None)
# New approach
migrations.RunPython(forwards, migrations.RunPython.noop)
]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24098>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0
Comment:
As discussed on IRC we should do the same thing for `RunSQL`.
An empty string `''` should work well to represent a provided no-op query
but we can also alias it to `RunSQL.noop` for consistency with
`RunPython`.
--
Ticket URL: <https://code.djangoproject.com/ticket/24098#comment:1>
* has_patch: 0 => 1
Comment:
PR: https://github.com/django/django/pull/3859
--
Ticket URL: <https://code.djangoproject.com/ticket/24098#comment:2>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/24098#comment:3>
* owner: => Tim Graham <timograham@…>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"c8bac4b556cf4716dc9003e5da48060cb72ba7cb"]:
{{{
#!CommitTicketReference repository=""
revision="c8bac4b556cf4716dc9003e5da48060cb72ba7cb"
Fixed #24098 -- Added no-op attributes to RunPython and RunSQL
Thanks Loïc Bistuer and Tim Graham for the discussion and review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24098#comment:4>