#25133: Changing a PositiveIntegerField to an IntegerField does not remove >=0
check in migration
-------------------------------------+-------------------------------------
Reporter: jproffitt | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: migrations, | Triage Stage:
postgres | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jproffitt):
* status: closed => new
* version: 1.7 => 1.8
* resolution: worksforme =>
Comment:
Sorry, I never knew someone responded. I am still having this issue. I am
using django 1.8.4 now. Here are the steps to reproduce:
1. Create a model with a `PositiveIntegerField`:
{{{
class MyModel(models.Model):
an_integer = models.PositiveIntegerField(null=True, blank=True)
}}}
2: create migrations, and you get this migration:
{{{
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.CreateModel(
name='MyModel',
fields=[
('id', models.AutoField(verbose_name='ID',
serialize=False, auto_created=True, primary_key=True)),
('an_integer', models.PositiveIntegerField(null=True,
blank=True)),
],
),
]
}}}
which generates this constraint in Postgres:
{{{
ALTER TABLE myproject.myapp_mymodel
ADD CONSTRAINT myapp_mymodel_an_integer_check CHECK (an_integer >= 0);
}}}
3. Change the `PositiveIntegerField` to a plain `IntegerField`:
{{{
class MyModel(models.Model):
an_integer = models.IntegerField(null=True, blank=True)
}}}
4. Make migrations again, and you get this migration:
{{{
class Migration(migrations.Migration):
dependencies = [
('myapp', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='mymodel',
name='an_integer',
field=models.IntegerField(null=True, blank=True),
),
]
}}}
But the constraint is still there in the database. To check, I can try to
create a record with a negative integer:
{{{
>>> from myapp.models import MyModel
>>> MyModel.objects.create(an_integer=-5)
...
IntegrityError: new row for relation "myapp_mymodel" violates check
constraint "myapp_mymodel_an_integer_check"
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25133#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.d6ae3ca55fda1afe065917d3620ddb70%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.