#31036: MySQL driver has incorrect primary key default, causing failure to 
insert
auto increment rows with no additional values.
-------------------------------------+-------------------------------------
     Reporter:  PeterVenable         |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  2.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  mysql                |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by PeterVenable:

Old description:

> 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'.

New description:

 The problem:

 Given a MySQL 5.6 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#comment:1>
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/070.14a017ad7dea1771219371f260d253cf%40djangoproject.com.

Reply via email to