@@ -53,7 +53,8 @@ def drop_constraints(self):
53
53
logger .debug (f"Dropping constraints from { self .model .__name__ } " )
54
54
with connection .schema_editor () as schema_editor :
55
55
# Remove any "unique_together" constraints
56
- if self .model ._meta .unique_together :
56
+ # NOTE: "unique_together" may be deprecated in the future
57
+ if getattr (self .model ._meta , 'unique_together' , False ):
57
58
logger .debug (
58
59
"Dropping unique_together of {}" .format (
59
60
self .model ._meta .unique_together
@@ -76,11 +77,12 @@ def drop_indexes(self):
76
77
"""
77
78
logger .debug (f"Dropping indexes from { self .model .__name__ } " )
78
79
with connection .schema_editor () as schema_editor :
79
- # Remove any "index_together" constraints
80
- logger .debug (
81
- f"Dropping index_together of { self .model ._meta .index_together } "
82
- )
83
- if self .model ._meta .index_together :
80
+ if getattr (self .model ._meta , 'index_together' , False ):
81
+ # Remove any "index_together" constraints
82
+ # NOTE: "index_together has been removed from Django 5.1
83
+ logger .debug (
84
+ f"Dropping index_together of { self .model ._meta .index_together } "
85
+ )
84
86
args = (self .model , self .model ._meta .index_together , ())
85
87
self .edit_schema (schema_editor , "alter_index_together" , args )
86
88
@@ -99,7 +101,8 @@ def restore_constraints(self):
99
101
logger .debug (f"Adding constraints to { self .model .__name__ } " )
100
102
with connection .schema_editor () as schema_editor :
101
103
# Add any "unique_together" contraints from the database
102
- if self .model ._meta .unique_together :
104
+ # NOTE: "unique_together" may be deprecated in the future
105
+ if getattr (self .model ._meta , 'unique_together' , False ):
103
106
logger .debug (
104
107
"Adding unique_together of {}" .format (
105
108
self .model ._meta .unique_together
@@ -122,8 +125,9 @@ def restore_indexes(self):
122
125
"""
123
126
logger .debug (f"Adding indexes to { self .model .__name__ } " )
124
127
with connection .schema_editor () as schema_editor :
125
- # Add any "index_together" contraints to the database.
126
- if self .model ._meta .index_together :
128
+ if getattr (self .model ._meta , 'index_together' , False ):
129
+ # Add any "index_together" contraints to the database.
130
+ # NOTE: "index_together has been removed from Django 5.1
127
131
logger .debug (
128
132
"Restoring index_together of {}" .format (
129
133
self .model ._meta .index_together
0 commit comments