#22705: can't bulk create models with no fields
-------------------------------------+-------------------------------------
Reporter: ellery-newcomer@… | Owner: chrisjluc
Type: Bug | Status: assigned
Component: Database layer | Version: 1.6
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by chrisjluc):
I've modified the compiler to create the below query, but I'm getting an
Integrity Error: datatype mismatch when I run it in Django. I assume it's
because `id` is a pk and it doesn't accept `NULL` values, but it seems to
work on my own sqlite. Does anyone know how to solve this issue?
We use the second form of bulk inserting, ref
https://www.sqlite.org/lang_insert.html
`u'INSERT INTO "bulk_create_nofields" ("id") SELECT %s UNION ALL SELECT %s
UNION ALL SELECT %s', (u'NULL', u'NULL', u'NULL'))`
{{{
Traceback (most recent call last):
File
"/Users/chrisjluc/Documents/opensource/django/tests/bulk_create/tests.py",
line 172, in test_empty_model
NoFields.objects.bulk_create(objs)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/models/manager.py",
line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/models/query.py",
line 445, in bulk_create
self._batched_insert(objs_without_pk, fields, batch_size)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/models/query.py",
line 1043, in _batched_insert
using=self.db)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/models/manager.py",
line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/models/query.py",
line 1026, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/models/sql/compiler.py",
line 974, in execute_sql
cursor.execute(sql, params)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/backends/utils.py",
line 64, in execute
return self.cursor.execute(sql, params)
File "/Users/chrisjluc/Documents/opensource/django/django/db/utils.py",
line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/backends/utils.py",
line 64, in execute
return self.cursor.execute(sql, params)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/backends/sqlite3/base.py",
line 318, in execute
return Database.Cursor.execute(self, query, params)
IntegrityError: datatype mismatch
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22705#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/084.439f421e50863cee93ff8818785620ef%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.