mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Allow callables as the argument to RunPython
This commit is contained in:
@@ -332,6 +332,15 @@ class OperationTests(MigrationTestBase):
|
||||
# And test reversal fails
|
||||
with self.assertRaises(NotImplementedError):
|
||||
operation.database_backwards("test_runpython", None, new_state, project_state)
|
||||
# Now test we can do it with a callable
|
||||
def inner_method(models, schema_editor):
|
||||
Pony = models.get_model("test_runpython", "Pony")
|
||||
Pony.objects.create(pink=1, weight=3.55)
|
||||
Pony.objects.create(weight=5)
|
||||
operation = migrations.RunPython(inner_method)
|
||||
with connection.schema_editor() as editor:
|
||||
operation.database_forwards("test_runpython", editor, project_state, new_state)
|
||||
self.assertEqual(project_state.render().get_model("test_runpython", "Pony").objects.count(), 4)
|
||||
|
||||
|
||||
class MigrateNothingRouter(object):
|
||||
|
||||
Reference in New Issue
Block a user