#31036: MySQL driver has incorrect primary key default, causing failure to
insert
auto increment rows with no additional values.
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
PeterVenable |
Type: Bug | Status: new
Component: Database | Version: 2.2
layer (models, ORM) |
Severity: Normal | Keywords: mysql
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
The problem:
Given a MySQL table with only one column, an auto-increment primary key
integer, inserting a row should be as simple as calling
MyTable.objects.create()
However, the generated SQL is:
{{{
INSERT INTO `myapp_mytable` (`id`) VALUES (DEFAULT);
-- Error Code: 1062. Duplicate entry '0' for key 'PRIMARY'
}}}
Instead it should generate:
{{{
INSERT INTO `myapp_mytable` (`id`) VALUES (NULL);
}}}
The fix could be a one-line edit to
https://github.com/django/django/blob/master/django/db/backends/base/operations.py#L294
changing 'DEFAULT' to 'NULL'.
--
Ticket URL: <https://code.djangoproject.com/ticket/31036>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/055.75dab0440c7b0d502e09906e7a877132%40djangoproject.com.