Opened 10 years ago
Closed 10 years ago
#22637 closed Bug (invalid)
Documentation not clear about the effects of max_length for IntegerField
Reported by: | Owned by: | ||
---|---|---|---|
Component: | Documentation | Version: | 1.7-beta-2 |
Severity: | Normal | Keywords: | |
Cc: | Andrew Godwin | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
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.
Change History (5)
comment:1 by , 10 years ago
Component: | Migrations → Documentation |
---|---|
Easy pickings: | set |
Summary: | Django migrations ignore max_length for IntegerField → Documentation not clear about the effects of max_length for IntegerField |
comment:2 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
I am working on this on the Django Con
comment:3 by , 10 years ago
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
.
comment:4 by , 10 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:5 by , 10 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
I don't think there's value in documenting parameters that don't appear in the documentation have no effect.
Hello,
Thanks for taking care to submit this detailed report. Actually,
max_length
is not a documented option forIntegerField
, 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.