Opened 5 years ago

Last modified 5 years ago

#31036 closed Bug

MySQL driver has incorrect primary key default, causing failure to insert auto increment rows with no additional values. — at Version 1

Reported by: Peter Venable Owned by: nobody
Component: Database layer (models, ORM) Version: 2.2
Severity: Normal Keywords: mysql
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Peter Venable)

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

Change History (1)

comment:1 by Peter Venable, 5 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top