You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an existing model that has existing data that I would like to start tracking history on. I found that by editing an instance for the first time after adding history that the event created didn't capture a diff, so I decide to create dummy "insert" events utilising create_event() as part of the migration file generated by adding the @pghistory.track decorator to the mode.
This worked fine locally however when deploying I've got the following error: ""insert" is not a registered tracker label for model MyModel". Am I doing something wrong? The "insert" label is the label of a newly created MyModel object after the history tracking was set up.
Relevant code below:
models.py
@pghistory.track()
class MyModel(models.Model):
...
0123_migration_file.py
def create_dummy_insert_events(apps, schema_editor):
MyModel = apps.get_model("myapp", "MyModel ")
for mymodel in MyModel .objects.all():
pghistory.create_event(mymodel , label="insert")
class Migration(migrations.Migration):
migrations.CreateModel(
name="MyModelEvent",
...
migrations.RunPython(create_dummy_insert_events, migrations.RunPython.noop),
Thanks in advance!
The text was updated successfully, but these errors were encountered:
I since found issue #94 which I found useful and allowed me to make progress. I would like to understand further why you'd need to reference the model itself and not through the app registry, especially since this is as recommended by the Django docs? 🤔
I also personally would think it would be nice functionality to default create those initial Event objects for any existing data (or at least configurable in case you didn't want it). Or instead update so that the first update Event logged on an existing instance captures a diff. Happy to make this a discussion if it's better placed as one 🙂
Hi there 👋
I have an existing model that has existing data that I would like to start tracking history on. I found that by editing an instance for the first time after adding history that the event created didn't capture a diff, so I decide to create dummy "insert" events utilising
create_event()
as part of the migration file generated by adding the@pghistory.track
decorator to the mode.This worked fine locally however when deploying I've got the following error: ""insert" is not a registered tracker label for model MyModel". Am I doing something wrong? The "insert" label is the label of a newly created MyModel object after the history tracking was set up.
Relevant code below:
Thanks in advance!
The text was updated successfully, but these errors were encountered: