[Django] #22637: Django migrations ignore max_length for IntegerField

63 views
Skip to first unread message

Django

unread,
May 16, 2014, 10:45:45 AM5/16/14
to django-...@googlegroups.com
#22637: Django migrations ignore max_length for IntegerField
----------------------------+------------------------
Reporter: msn@… | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------
With a model like this:

{{{
from django.db import models


class Dummy(models.Model):
id = models.IntegerField(max_length=10, primary_key=True)
}}}

`makemigrations` creates:

{{{
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='Dummy',
fields=[
('id', models.IntegerField(max_length=10, serialize=False,
primary_key=True)),
],
options={
},
bases=(models.Model,),
),
]
}}}

After running the migration I run the following MySQL:

{{{
mysql> describe dummy_dummy;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
+-------+---------+------+-----+---------+-------+
1 row in set (0,01 sec)
}}}

I expected type to be `int(10)` but instead I get `int(11)` which is the
default for `IntegerField`. Not sure if this is expected behavior or not,
but I'd expect the `max_length` parameter to alter the type. If that's not
the case I'd be glad to hear if there's another way to alter it.

--
Ticket URL: <https://code.djangoproject.com/ticket/22637>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 16, 2014, 11:26:12 AM5/16/14
to django-...@googlegroups.com
#22637: Documentation not clear about the effects of max_length for IntegerField
-------------------------------+--------------------------------------

Reporter: msn@… | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.7-beta-2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by shai):

* needs_better_patch: => 0
* component: Migrations => Documentation
* needs_tests: => 0
* easy: 0 => 1
* needs_docs: => 0


Comment:

Hello,

Thanks for taking care to submit this detailed report. Actually,
`max_length` is not a documented option for `IntegerField`, and AFAIK it
only modifies the widget that is generated for the field in forms by
default.

If you want to specify exactly the parameters of a numeric database
column, use `DecimalField`.

I am recasting this as a documentation bug.

--
Ticket URL: <https://code.djangoproject.com/ticket/22637#comment:1>

Django

unread,
May 16, 2014, 11:45:02 AM5/16/14
to django-...@googlegroups.com
#22637: Documentation not clear about the effects of max_length for IntegerField
-------------------------------+-----------------------------------------
Reporter: msn@… | Owner: sabinemaennel
Type: Bug | Status: assigned

Component: Documentation | Version: 1.7-beta-2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+-----------------------------------------
Changes (by sabinemaennel):

* owner: nobody => sabinemaennel
* status: new => assigned


Comment:

I am working on this on the Django Con

--
Ticket URL: <https://code.djangoproject.com/ticket/22637#comment:2>

Django

unread,
May 16, 2014, 2:18:46 PM5/16/14
to django-...@googlegroups.com
#22637: Documentation not clear about the effects of max_length for IntegerField
-------------------------------+-----------------------------------------
Reporter: msn@… | Owner: sabinemaennel
Type: Bug | Status: assigned
Component: Documentation | Version: 1.7-beta-2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+-----------------------------------------

Comment (by sabinemaennel):

Hello ,
I just tested this. This is my result:

Assigning the option `max_length` to an `IntegerField` in your model does
not have any effect, neither on the database where the field is just
generated as an `models.IntegerField()` nor on the Admin Form, where the
field is always generated as `"type=text"`and `class="vIntegerField"`. So
it does not really make sense to have that option here.

I talked about this with chai about this and the opinion was that the
option should not be forbidden in order to keep Django upward compatible,
but that it also does not make sense for the `IntegerField`.

--
Ticket URL: <https://code.djangoproject.com/ticket/22637#comment:3>

Django

unread,
May 16, 2014, 2:22:08 PM5/16/14
to django-...@googlegroups.com
#22637: Documentation not clear about the effects of max_length for IntegerField
-------------------------------+--------------------------------------
Reporter: msn@… | Owner:
Type: Bug | Status: new

Component: Documentation | Version: 1.7-beta-2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by sabinemaennel):

* owner: sabinemaennel =>
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/22637#comment:4>

Django

unread,
May 16, 2014, 8:13:22 PM5/16/14
to django-...@googlegroups.com
#22637: Documentation not clear about the effects of max_length for IntegerField
-------------------------------+--------------------------------------
Reporter: msn@… | Owner:
Type: Bug | Status: closed
Component: Documentation | Version: 1.7-beta-2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by timo):

* status: new => closed
* resolution: => invalid


Comment:

I don't think there's value in documenting parameters that don't appear in
the documentation have no effect.

--
Ticket URL: <https://code.djangoproject.com/ticket/22637#comment:5>

Reply all
Reply to author
Forward
0 new messages