django-simple-history icon indicating copy to clipboard operation
django-simple-history copied to clipboard

It appears the simple-history is incompatible with model_utils.models.UUIDModel

Open matteius opened this issue 2 years ago • 1 comments

Describe the bug It appears the simple-history is incompatible with model_utils.models.UUIDModel. Despite my best efforts, it attempts to have two primary_key values on the history table always.

To Reproduce Steps to reproduce the behavior:

  1. Create a basic model that works with Django simple-history and add in the history = HistoricalRecords() manager. Verify it is working,
  2. Destroy the prior migration and table and modify your test model to inherit from model_utils.models.UUIDModel
  3. Make a new migration and note that it attempts to have two primary_key values on the history table.
  4. Attempt to migrate and see error

Expected behavior Should be able to create a history table with a UUID primary key, based off the jazzband model_utils.models.UUIDModel

Environment (please complete the following information):

  • OS: ubuntu-latest
  • Browser (if applicable): n/a
  • Django Simple History Version: 3.0.0
  • Django Version: 3.2.13
  • Database Version: PostgreSQL

Additional context We want to use both things but are using simple history with regular AI integer PKs until this issue can be fixed.

matteius avatar May 09 '22 15:05 matteius

yes facing the same problem here also with the default django models.uuid. I know it's stated in the documentation but maybe we should give the option for users to choose their primary key? Note: regardless of what field type you specify as your history_id field, that field will automatically set primary_key=True and editable=False.

class Meta(TimeStampedModel):
    history = HistoricalRecords(inherit=True)
    id = SmallUUIDField(default=uuid_default(), editable=False, primary_key=True)

causes an error to be raised

DETAIL:  Key (id)=(319a9473-6717-4254-bc03-58e26590ffc9) already exists.```

I think the library was relying on the autoincrement to create different versions of the history. 

HaddadJoe avatar Jan 10 '23 23:01 HaddadJoe