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.
--
Ticket URL: <https://code.djangoproject.com/ticket/24365>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* component: Database layer (models, ORM) => Core (Management commands)
* needs_tests: => 0
* version: 1.7 => master
* needs_docs: => 0
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24365#comment:1>
* keywords: inspectdb, unsigned, positiveintegerfield => inspectdb,
unsigned, positiveintegerfield, mysql
Comment:
AFAIK, this is a MySQL specific issue, as other backends don't care about
signed/unsigned.
--
Ticket URL: <https://code.djangoproject.com/ticket/24365#comment:2>
Comment (by bharadwaj6):
Replying to [comment:2 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. :)
--
Ticket URL: <https://code.djangoproject.com/ticket/24365#comment:3>
Comment (by claudep):
Feel free to try. I can assist you if needed.
--
Ticket URL: <https://code.djangoproject.com/ticket/24365#comment:4>
* status: new => assigned
* owner: nobody => earthling-shruti
--
Ticket URL: <https://code.djangoproject.com/ticket/24365#comment:5>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/24365#comment:6>
* owner: earthling-shruti =>
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/24365#comment:7>
* owner: (none) => felixxm
* needs_better_patch: 1 => 0
* has_patch: 1 => 0
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/24365#comment:8>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/8151 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/24365#comment:9>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"94d8bea212441ebfafcab10d245285581e701c54" 94d8bea2]:
{{{
#!CommitTicketReference repository=""
revision="94d8bea212441ebfafcab10d245285581e701c54"
Fixed #24365 -- Made inspectdb translate MySQL unsigned integer columns to
positive integer fields.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24365#comment:10>