Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple-django-history not compatible with TimeflakePrimaryKeyBinary #14

Open
bcastorBTO opened this issue Dec 1, 2022 · 0 comments
Open
Labels
bug Something isn't working

Comments

@bcastorBTO
Copy link

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!

@anthonynsimon anthonynsimon added the bug Something isn't working label Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants