Skip to content

Commit e64db03

Browse files
replace deprecated unique_together / index_together, fixes #530
1 parent d692935 commit e64db03

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Generated by Junie to replace deprecated unique_together and index_together
2+
from django.db import migrations, models
3+
4+
5+
class Migration(migrations.Migration):
6+
dependencies = [
7+
("main", "0013_alter_host_update_secret"),
8+
]
9+
10+
operations = [
11+
# Remove deprecated Meta options
12+
migrations.AlterUniqueTogether(
13+
name="host",
14+
unique_together=set(),
15+
),
16+
migrations.AlterIndexTogether(
17+
name="host",
18+
index_together=set(),
19+
),
20+
migrations.AlterUniqueTogether(
21+
name="relatedhost",
22+
unique_together=set(),
23+
),
24+
# Add explicit constraints
25+
migrations.AddConstraint(
26+
model_name="host",
27+
constraint=models.UniqueConstraint(
28+
fields=("name", "domain"), name="unique_host_domain"
29+
),
30+
),
31+
migrations.AddConstraint(
32+
model_name="relatedhost",
33+
constraint=models.UniqueConstraint(
34+
fields=("name", "main_host"), name="unique_relatedhost_name_mainhost"
35+
),
36+
),
37+
]

src/nsupdate/main/models.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,9 @@ def __str__(self):
258258
return u"%s.%s" % (self.name, self.domain.name)
259259

260260
class Meta(object):
261-
# deprecated, but works:
262-
unique_together = (('name', 'domain'),)
263-
index_together = (('name', 'domain'),)
264-
# this seems to be the new way, but it does not work:
265-
# ValueError: Found wrong number (2) of indexes for main_host(name, domain_id).
266-
# constraints = [models.constraints.UniqueConstraint(fields=['name', 'domain'], name='unique_host_domain')]
267-
# indexes = [models.Index(fields=['name', 'domain'])]
261+
constraints = [
262+
models.UniqueConstraint(fields=['name', 'domain'], name='unique_host_domain'),
263+
]
268264
verbose_name = _('host')
269265
verbose_name_plural = _('hosts')
270266
ordering = ('domain', 'name') # groupby domain and sort by name
@@ -421,7 +417,9 @@ def __str__(self):
421417
return u"%s.%s" % (self.name, str(self.main_host))
422418

423419
class Meta(object):
424-
unique_together = (('name', 'main_host'),)
420+
constraints = [
421+
models.UniqueConstraint(fields=['name', 'main_host'], name='unique_relatedhost_name_mainhost'),
422+
]
425423
verbose_name = _('related host')
426424
verbose_name_plural = _('related hosts')
427425
ordering = ('main_host', 'name')

0 commit comments

Comments
 (0)