ValueError: Can't bulk create a multi-table inherited model
See original GitHub issueProblem
I have a super Notification(models.Model) class which I use to create many notification subclasses such as PostNotification(Notification), CommentNotification(Notification), etc., and when trying to run CommentNotification.objects.bulk_create(my_list_of_notification_objects), i get the following traceback:
File "/home/me/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/models/query.py", line 429, in bulk_create
raise ValueError("Can't bulk create a multi-table inherited model")
ValueError: Can't bulk create a multi-table inherited model
and upon inspecting the query.py file, we get this causes the error:
for parent in self.model._meta.get_parent_list():
if parent._meta.concrete_model is not self.model._meta.concrete_model:
raise ValueError("Can't bulk create a multi-table inherited model")
Environment
- Django Model Utils version: 3.1.1
- Django version: 1.11.7
- Python version: 2.7.3
Example
PostNotification.objects.bulk_create(
[PostNotification(related_user=user, post=instance) for user in users]
)
throws the above exception
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
Django "ValueError: Can't bulk create a multi-table inherited ...
The trick is create a model (which is not an inherited one) dynamically that has some meta (db_table) set. And use this dynamic...
Read more >#24997 (Allow bulk_create with proxy inheritance) – Django
_meta.parents: raise ValueError("Can't bulk create an inherited model"). This test does not discriminate between multi-table inheritance and proxy ...
Read more >Can't bulk create a multi-table inherited model"-django
Found a hacky solution. I hope it works in your case. The trick is create a model (which is not an inherited one)...
Read more >bulk_create for multi table inheritance support - Google Groups
For sqlite we can only support bulk_create if the model does not have a parent with an AutoField. for MySQL I think we...
Read more >ValueError: Can't bulk create a multi-table inherited model
ValueError : Can't bulk create a multi-table inherited model. ... Model) class which I use to create many notification subclasses such as ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

CORRECTION: IT WAS NOT ACTUALLY FIXED!
running
Notification.objects.bulk_create([SubClassNotification(<vals>),SubClassNotification(<vals>)]only creates base class Notification objects and subsequently runningSubClassNotification.objects.all()returns an empty queryset.I believe the issue is impossible to fix. My solution months ago was to redo the wntire notification backend and just use a single Notification() model with a type char selection field to differentiate the type of notification that it was