Example:
class UniqueField(models.CharField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("unique", True)
super().__init__(*args, **kwargs)
@pghistory.track()
class Foo(models.Model):
slug = UniqueField()
Which leads to following migration:
migrations.CreateModel(
name='Foo',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('slug', foo_app.models.UniqueField(unique=True)),
],
),
migrations.CreateModel(
name='FooEvent',
fields=[
('pgh_id', models.AutoField(primary_key=True, serialize=False)),
('pgh_created_at', models.DateTimeField(auto_now_add=True)),
('pgh_label', models.TextField(help_text='The event label.')),
('id', models.IntegerField()),
('slug', foo_app.models.UniqueField(unique=True)),
],
options={
'abstract': False,
},
),
I think that FooEvent shouldn't have slug field with unique constraint as it prevents multiple tracking events for same Foo record.
Next, it is working correctly for plain CharField with explicit unique=True (constraint is not present in the event model). The problem seems to be custom fields with implicit defaults which deviates from Django's defaults.
Thanks for any opinion to this topic.
Example:
Which leads to following migration:
I think that
FooEventshouldn't haveslugfield with unique constraint as it prevents multiple tracking events for sameFoorecord.Next, it is working correctly for plain
CharFieldwith explicitunique=True(constraint is not present in the event model). The problem seems to be custom fields with implicit defaults which deviates from Django's defaults.Thanks for any opinion to this topic.