Opened 10 years ago
Closed 10 years ago
#23505 closed Bug (needsinfo)
unique constraint tracking lost after DropColumn + AddColumn in postgres
Reported by: | Andrew Fink | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.7 |
Severity: | Normal | Keywords: | unique_together |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Reproduce:
- Create model with a multi-column uniqueness constraint in postgres
- Drop a column in the uniqueness constraint, then readd it with a different type.
e.g:
foo = models.IntegerField() # to foo = models.CharField(max_length=255)
- Attempt to modify the uniqueness constraint and run the subsequent migration. It fails with 'ValueError: Found wrong number (0) of constraints for <tablename>'
This is likely due to django not tracking postgres automatically dropping the uniqueness constraint when a column is deleted/added.
See 'Description -> DROP COLUMN':
http://www.postgresql.org/docs/9.1/static/sql-altertable.html
Change History (2)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Hi,
Could you give us some more details on how to reproduce the issue?
I tried using this model:
Then I ran
makemigrations
andmigrate
.After that, I changed the
bar
field tobar = models.CharField(max_length=10)
and ranmakemigrations
andmigrate
again.But when I do that, I can see that the unique constraint is still there:
Thanks.