Skip to content

simple-django-history not compatible with TimeflakePrimaryKeyBinary #14

@bcastorBTO

Description

@bcastorBTO

Lets say you have the following model and want to add history tracking to each FooModel object:

from simple_history.models import HistoricalRecords

class FooModel(models.Model):
   id = TimeflakePrimaryKeyBinary()
   history = HistoricalRecords(
        history_id_field=models.UUIDField(default=uuid.uuid4)
    )

It generates the following error during makemigrations:
venv/lib/python3.9/site-packages/timeflake/extensions/django/__init__.py", line 97, in deconstruct del kwargs["primary_key"] KeyError: 'primary_key'

However, I tried adding the following try/except around this code and the migration would generate without an issue:
image

Downside is that leads to this error when trying to execute the migration:
django.db.utils.ProgrammingError: multiple primary keys for table "requisition_data_historicalrequisitionmodel" are not allowed LINE 1: ...me" varchar(200) NULL, "history_id" uuid NOT NULL PRIMARY KE...

So at the end of the day any model that uses TimeflakePrimaryKeyBinary for a primary ky id field is unable to track object history using https://django-simple-history.readthedocs.io/en/latest/ which is a deficit.

I can manually adjust the migration after the fact to "work" (i.e. be a charfied or uuid field etc with primary_key = False) but django will not honor the change and all subsequent makemigrations commands will try to undo the changes.

Can this issue be investigated? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions