{{{
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.
* 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>
* 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>
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>
* owner: sabinemaennel =>
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/22637#comment:4>
* 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>