Opened 10 years ago
Closed 8 years ago
#24365 closed Bug (fixed)
inspectdb should generate PositiveIntegerFields for unsigned fields.
Reported by: | Bharadwaj Srigiriraju | Owned by: | Mariusz Felisiak |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Normal | Keywords: | inspectdb, unsigned, positiveintegerfield, mysql |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have tested this on MySQL and Django 1.7.4.
I have unsigned integer fields in my mysql table (which can be created from SQL like this: entity_id int(10) unsigned NOT NULL COMMENT 'Entity ID'
), and when I introspect a table that contains fields like this, the corresponding model field generated is:
entity_id = models.IntegerField()
,
whereas it should be something like:
entity_id = models.PositiveIntegerField()
.
This is same in case of unsigned smallint fields too.
A bug like this also breaks ForeignKey relationships on that field, as the new field created would be a normal INT and results in MySQL error 150 during migrations and breaks them. Changing the fields to PositiveIntegerField
in generated file manually seems like the only fix for now (which was suggested to me on #django IRC).
So, inspectdb
should generate PositiveIntegerField
when the field is unsigned. I am not sure if this is the same for other databases too, as I haven't tested against them.
Change History (10)
comment:1 by , 10 years ago
Component: | Database layer (models, ORM) → Core (Management commands) |
---|---|
Triage Stage: | Unreviewed → Accepted |
Version: | 1.7 → master |
follow-up: 3 comment:2 by , 10 years ago
Keywords: | mysql added |
---|
comment:3 by , 10 years ago
Replying to claudep:
AFAIK, this is a MySQL specific issue, as other backends don't care about signed/unsigned.
Is this issue an easy picking?
If yes, I would like to fix this myself. :)
comment:5 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:6 by , 9 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
comment:7 by , 9 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:8 by , 8 years ago
Has patch: | unset |
---|---|
Owner: | set to |
Patch needs improvement: | unset |
Status: | new → assigned |
AFAIK, this is a MySQL specific issue, as other backends don't care about signed/unsigned.