Opened 11 years ago
Closed 11 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 , 11 years ago
comment:2 by , 11 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
makemigrationsandmigrate.After that, I changed the
barfield tobar = models.CharField(max_length=10)and ranmakemigrationsandmigrateagain.But when I do that, I can see that the unique constraint is still there:
Table "public.bug23505_foo" Column | Type | Modifiers --------+-----------------------+----------------------------------------------------------- id | integer | not null default nextval('bug23505_foo_id_seq'::regclass) foo | integer | not null bar | character varying(10) | not null Indexes: "bug23505_foo_pkey" PRIMARY KEY, btree (id) "bug23505_foo_foo_30361d88471c726e_uniq" UNIQUE CONSTRAINT, btree (foo, bar)Thanks.