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

Not null constraint fails with inheritance and m2m fields #1354

Open
b1rger opened this issue Jun 11, 2024 · 0 comments
Open

Not null constraint fails with inheritance and m2m fields #1354

b1rger opened this issue Jun 11, 2024 · 0 comments

Comments

@b1rger
Copy link

b1rger commented Jun 11, 2024

Describe the bug

Oke, so, thats a weird one, I think. I get an IntegrityError when I try to load fixtures if I use inheritance and an m2m field:

django.db.utils.IntegrityError: Problem installing fixture '/path/to/foobar/fixtures/foobar.json': Could not load foobar.Person(pk=1): NOT NULL constraint failed: foobar_historicalperson.id

This happens when I use both multi table inheritance and I set the _history_m2m_fields.

To Reproduce

I have pushed a minimal reproducer to https://github.com/b1rger/dsh-reproducer
I have the following models.py:

class Root(models.Model):
    pass

class Profession(models.Model):
    name = models.CharField(max_length=8)


class Person(Root):
    _history_m2m_fields = ["profession"]
    profession = models.ManyToManyField(Profession, blank=True)
    history = HistoricalRecords()

I created the instance by running:

pro = Profession.objects.create()
p = Person.objects.create()
p.profession.add(pro)

then I dumped the fixture using dumpdata foobar. When I try to load the fixture I get the error above.

Expected behavior
No IntegrityError, but the data imported.

Environment (please complete the following information):

  • OS: Debian unstable
  • Django Simple History Version: 3.7.0
  • Django Version: 5.0.6
  • Database Version: sqlite 3.40
b1rger added a commit to acdh-oeaw/apis-core-rdf that referenced this issue Jun 18, 2024
version 3.6 of simple history fixes this bug:
jazzband/django-simple-history#1328 which is
useful when we want to disable simple history to circumvent this bug
jazzband/django-simple-history#1354
b1rger added a commit to acdh-oeaw/apis-core-rdf that referenced this issue Jun 19, 2024
version 3.6 of simple history fixes this bug:
jazzband/django-simple-history#1328 which is
useful when we want to disable simple history to circumvent this bug
jazzband/django-simple-history#1354
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant