Ticket #83 (closed defect: fixed)
alter_table does not take care of constraints
| Reported by: | ck@… | Owned by: | andrew |
|---|---|---|---|
| Priority: | major | Milestone: | 0.5 |
| Component: | commands | Version: | 0.4 |
| Keywords: | Cc: |
Description
When trying to convert a PositiveSmallIntegerField? to a SmallIntegerField? alter_table does not drop the constraints that take care of the values being positive.
So when doing something like this:
def forwards(self):
db.alter_column('forum_category', 'order', models.SmallIntegerField(default=0))
def backwards(self):
db.alter_column('forum_category', 'order', models.PositiveSmallIntegerField(default=0))
The migration will run without problems but effectively does nothing.
Attachments
Change History
comment:2 Changed 4 years ago by andrew
- Status changed from new to assigned
- Milestone set to 0.5
Indeed, that's a good find. I'll try to fix it in the next week or so.
comment:3 Changed 4 years ago by andrew
- Status changed from assigned to closed
- Resolution set to fixed
OK, this is a tough one. [224] contains a fix for the problem here, but there's still the problem of adding the constraint back in when the column is converted back; things like this may well need a patch to Django core, and in the interim a dict of special cases, so columns can give their constraints properly rather than assuming the types are going into a CREATE TABLE.
Anyway, only Postgres supports this constraint at the moment anyway, so Django must be checking for it Python-side anyway, so closing this one as fixed.

Oh sorry, forgot to select the right component.