@@ -2266,10 +2266,9 @@ def test_same_app_circular_fk_dependency_with_unique_together_and_indexes(self):
2266
2266
changes ,
2267
2267
"eggs" ,
2268
2268
0 ,
2269
- ["CreateModel" , "CreateModel" , "AddIndex" , "AlterUniqueTogether" ],
2269
+ ["CreateModel" , "CreateModel" ],
2270
2270
)
2271
2271
self .assertNotIn ("unique_together" , changes ["eggs" ][0 ].operations [0 ].options )
2272
- self .assertNotIn ("unique_together" , changes ["eggs" ][0 ].operations [1 ].options )
2273
2272
self .assertMigrationDependencies (changes , "eggs" , 0 , [])
2274
2273
2275
2274
def test_alter_db_table_add (self ):
@@ -2565,6 +2564,9 @@ def test(from_state, to_state, msg):
2565
2564
2566
2565
def test_create_model_with_indexes (self ):
2567
2566
"""Test creation of new model with indexes already defined."""
2567
+ added_index = models .Index (
2568
+ fields = ["name" ], name = "create_model_with_indexes_idx"
2569
+ )
2568
2570
author = ModelState (
2569
2571
"otherapp" ,
2570
2572
"Author" ,
@@ -2573,25 +2575,25 @@ def test_create_model_with_indexes(self):
2573
2575
("name" , models .CharField (max_length = 200 )),
2574
2576
],
2575
2577
{
2576
- "indexes" : [
2577
- models .Index (fields = ["name" ], name = "create_model_with_indexes_idx" )
2578
- ]
2578
+ "indexes" : [added_index ],
2579
2579
},
2580
2580
)
2581
2581
changes = self .get_changes ([], [author ])
2582
- added_index = models .Index (
2583
- fields = ["name" ], name = "create_model_with_indexes_idx"
2584
- )
2585
2582
# Right number of migrations?
2586
2583
self .assertEqual (len (changes ["otherapp" ]), 1 )
2587
2584
# Right number of actions?
2588
2585
migration = changes ["otherapp" ][0 ]
2589
- self .assertEqual (len (migration .operations ), 2 )
2586
+ self .assertEqual (len (migration .operations ), 1 )
2590
2587
# Right actions order?
2591
- self .assertOperationTypes (changes , "otherapp" , 0 , ["CreateModel" , "AddIndex" ])
2588
+ self .assertOperationTypes (changes , "otherapp" , 0 , ["CreateModel" ])
2592
2589
self .assertOperationAttributes (changes , "otherapp" , 0 , 0 , name = "Author" )
2593
2590
self .assertOperationAttributes (
2594
- changes , "otherapp" , 0 , 1 , model_name = "author" , index = added_index
2591
+ changes ,
2592
+ "otherapp" ,
2593
+ 0 ,
2594
+ 0 ,
2595
+ name = "Author" ,
2596
+ options = {"indexes" : [added_index ]},
2595
2597
)
2596
2598
2597
2599
def test_add_indexes (self ):
@@ -3984,62 +3986,69 @@ def test_add_model_order_with_respect_to_unique_together(self):
3984
3986
},
3985
3987
)
3986
3988
3987
- def test_add_model_order_with_respect_to_index_constraint (self ):
3988
- tests = [
3989
- (
3990
- "AddIndex" ,
3991
- {
3992
- "indexes" : [
3993
- models .Index (fields = ["_order" ], name = "book_order_idx" ),
3994
- ]
3995
- },
3996
- ),
3997
- (
3998
- "AddConstraint" ,
3999
- {
4000
- "constraints" : [
4001
- models .CheckConstraint (
4002
- check = models .Q (_order__gt = 1 ),
4003
- name = "book_order_gt_1" ,
4004
- ),
4005
- ]
4006
- },
4007
- ),
4008
- ]
4009
- for operation , extra_option in tests :
4010
- with self .subTest (operation = operation ):
4011
- after = ModelState (
4012
- "testapp" ,
4013
- "Author" ,
4014
- [
4015
- ("id" , models .AutoField (primary_key = True )),
4016
- ("name" , models .CharField (max_length = 200 )),
4017
- ("book" , models .ForeignKey ("otherapp.Book" , models .CASCADE )),
4018
- ],
4019
- options = {
4020
- "order_with_respect_to" : "book" ,
4021
- ** extra_option ,
4022
- },
4023
- )
4024
- changes = self .get_changes ([], [self .book , after ])
4025
- self .assertNumberMigrations (changes , "testapp" , 1 )
4026
- self .assertOperationTypes (
4027
- changes ,
4028
- "testapp" ,
4029
- 0 ,
4030
- [
4031
- "CreateModel" ,
4032
- operation ,
4033
- ],
4034
- )
4035
- self .assertOperationAttributes (
4036
- changes ,
4037
- "testapp" ,
4038
- 0 ,
4039
- 0 ,
4040
- name = "Author" ,
4041
- options = {"order_with_respect_to" : "book" },
4042
- )
3989
+ def test_add_model_order_with_respect_to_constraint (self ):
3990
+ after = ModelState (
3991
+ "testapp" ,
3992
+ "Author" ,
3993
+ [
3994
+ ("id" , models .AutoField (primary_key = True )),
3995
+ ("name" , models .CharField (max_length = 200 )),
3996
+ ("book" , models .ForeignKey ("otherapp.Book" , models .CASCADE )),
3997
+ ],
3998
+ options = {
3999
+ "order_with_respect_to" : "book" ,
4000
+ "constraints" : [
4001
+ models .CheckConstraint (
4002
+ check = models .Q (_order__gt = 1 ), name = "book_order_gt_1"
4003
+ ),
4004
+ ],
4005
+ },
4006
+ )
4007
+ changes = self .get_changes ([], [self .book , after ])
4008
+ self .assertNumberMigrations (changes , "testapp" , 1 )
4009
+ self .assertOperationTypes (
4010
+ changes ,
4011
+ "testapp" ,
4012
+ 0 ,
4013
+ ["CreateModel" , "AddConstraint" ],
4014
+ )
4015
+ self .assertOperationAttributes (
4016
+ changes ,
4017
+ "testapp" ,
4018
+ 0 ,
4019
+ 0 ,
4020
+ name = "Author" ,
4021
+ options = {"order_with_respect_to" : "book" },
4022
+ )
4023
+
4024
+ def test_add_model_order_with_respect_to_index (self ):
4025
+ after = ModelState (
4026
+ "testapp" ,
4027
+ "Author" ,
4028
+ [
4029
+ ("id" , models .AutoField (primary_key = True )),
4030
+ ("name" , models .CharField (max_length = 200 )),
4031
+ ("book" , models .ForeignKey ("otherapp.Book" , models .CASCADE )),
4032
+ ],
4033
+ options = {
4034
+ "order_with_respect_to" : "book" ,
4035
+ "indexes" : [models .Index (fields = ["_order" ], name = "book_order_idx" )],
4036
+ },
4037
+ )
4038
+ changes = self .get_changes ([], [self .book , after ])
4039
+ self .assertNumberMigrations (changes , "testapp" , 1 )
4040
+ self .assertOperationTypes (changes , "testapp" , 0 , ["CreateModel" ])
4041
+ self .assertOperationAttributes (
4042
+ changes ,
4043
+ "testapp" ,
4044
+ 0 ,
4045
+ 0 ,
4046
+ name = "Author" ,
4047
+ options = {
4048
+ "order_with_respect_to" : "book" ,
4049
+ "indexes" : [models .Index (fields = ["_order" ], name = "book_order_idx" )],
4050
+ },
4051
+ )
4043
4052
4044
4053
def test_set_alter_order_with_respect_to_index_constraint_unique_together (self ):
4045
4054
tests = [
0 commit comments