TitleSlugDescriptionModel has non unique SlugField
Author: wowkin2Created Aug 8, 2022Updated Aug 6, 2026
I found that TitleSlugDescriptionModel allows to have non-unique slugs:
class TitleSlugDescriptionModel(TitleDescriptionModel):
slug = AutoSlugField(_('slug'), populate_from='title')From implementation above it is not clear, but when you try to make a ForeignKey to slug field:
field = models.ForeignKey(MyModel, to_field="slug", on_delete=models.CASCADE)Django will raise exception:
ChildModel.field: (fields.E311) 'MyModel.slug' must be unique because it is referenced by a foreign key.
HINT: Add unique=True to this field or add a UniqueConstraint (without condition) in the model Meta.constraints.Looks like it happened after this issue https://github.com/django-extensions/django-extensions/issues/33, when they allowed non unique within this commit: https://github.com/django-extensions/django-extensions/commit/176fccfdde0704748cab75023e51682887e7c806
Propose to make it unique by default. Or is there any reasons why slug should be non-unique?
Source: django-extensions/django-extensions