Opened 5 years ago
Closed 5 years ago
#31036 closed Bug (worksforme)
Primary key has incorrect default on MySQL.
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 )
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 (2)
comment:1 by , 5 years ago
Description: | modified (diff) |
---|
comment:2 by , 5 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Summary: | MySQL driver has incorrect primary key default, causing failure to insert auto increment rows with no additional values. → Primary key has incorrect default on MySQL. |
Note:
See TracTickets
for help on using tickets.
DEFAULT
works completely fine forAUTO_INCREMENT
columns on MySQL. I'm not able to reproduce your issue.