mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #31831 -- Fixed migration operations ordering when adding order_with_respect_to and constraints/indexes.
This commit is contained in:
committed by
Mariusz Felisiak
parent
366a93f174
commit
58a336a674
@@ -2179,6 +2179,87 @@ class AutodetectorTests(TestCase):
|
||||
},
|
||||
)
|
||||
|
||||
def test_add_model_order_with_respect_to_index_constraint(self):
|
||||
tests = [
|
||||
(
|
||||
'AddIndex',
|
||||
{'indexes': [
|
||||
models.Index(fields=['_order'], name='book_order_idx'),
|
||||
]},
|
||||
),
|
||||
(
|
||||
'AddConstraint',
|
||||
{'constraints': [
|
||||
models.CheckConstraint(
|
||||
check=models.Q(_order__gt=1),
|
||||
name='book_order_gt_1',
|
||||
),
|
||||
]},
|
||||
),
|
||||
]
|
||||
for operation, extra_option in tests:
|
||||
with self.subTest(operation=operation):
|
||||
after = ModelState('testapp', 'Author', [
|
||||
('id', models.AutoField(primary_key=True)),
|
||||
('name', models.CharField(max_length=200)),
|
||||
('book', models.ForeignKey('otherapp.Book', models.CASCADE)),
|
||||
], options={
|
||||
'order_with_respect_to': 'book',
|
||||
**extra_option,
|
||||
})
|
||||
changes = self.get_changes([], [self.book, after])
|
||||
self.assertNumberMigrations(changes, 'testapp', 1)
|
||||
self.assertOperationTypes(changes, 'testapp', 0, [
|
||||
'CreateModel', operation,
|
||||
])
|
||||
self.assertOperationAttributes(
|
||||
changes,
|
||||
'testapp',
|
||||
0,
|
||||
0,
|
||||
name='Author',
|
||||
options={'order_with_respect_to': 'book'},
|
||||
)
|
||||
|
||||
def test_set_alter_order_with_respect_to_index_constraint_foo_together(self):
|
||||
tests = [
|
||||
(
|
||||
'AddIndex',
|
||||
{'indexes': [
|
||||
models.Index(fields=['_order'], name='book_order_idx'),
|
||||
]},
|
||||
),
|
||||
(
|
||||
'AddConstraint',
|
||||
{'constraints': [
|
||||
models.CheckConstraint(
|
||||
check=models.Q(_order__gt=1),
|
||||
name='book_order_gt_1',
|
||||
),
|
||||
]},
|
||||
),
|
||||
('AlterIndexTogether', {'index_together': {('name', '_order')}}),
|
||||
('AlterUniqueTogether', {'unique_together': {('id', '_order')}}),
|
||||
]
|
||||
for operation, extra_option in tests:
|
||||
with self.subTest(operation=operation):
|
||||
after = ModelState('testapp', 'Author', [
|
||||
('id', models.AutoField(primary_key=True)),
|
||||
('name', models.CharField(max_length=200)),
|
||||
('book', models.ForeignKey('otherapp.Book', models.CASCADE)),
|
||||
], options={
|
||||
'order_with_respect_to': 'book',
|
||||
**extra_option,
|
||||
})
|
||||
changes = self.get_changes(
|
||||
[self.book, self.author_with_book],
|
||||
[self.book, after],
|
||||
)
|
||||
self.assertNumberMigrations(changes, 'testapp', 1)
|
||||
self.assertOperationTypes(changes, 'testapp', 0, [
|
||||
'AlterOrderWithRespectTo', operation,
|
||||
])
|
||||
|
||||
def test_alter_model_managers(self):
|
||||
"""
|
||||
Changing the model managers adds a new operation.
|
||||
|
||||
Reference in New Issue
Block a user