Opened 7 years ago
Last modified 7 years ago
#28339 new Cleanup/optimization
Setting db_index=False on a field doesn't actually remove the index — at Version 4
Reported by: | Craig de Stigter | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.11 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
- Make a field with
db_index=True
(forForeignKey
, django sets this by default) - Make a migration. This creates an index:
CREATE INDEX "a_c_b_id_5a026661" ON "a_c" ("b_id");
- Explicitly set
db_index=False
and create another migration - Check
sqlmigrate
for the new migration. Index is never actually removed:
BEGIN; -- -- Alter field b on c -- COMMIT;
One note: This is with postgres settings. I'm not sure if it's db-specific.
Change History (4)
comment:2 by , 7 years ago
Type: | Uncategorized → Bug |
---|
comment:3 by , 7 years ago
Turns out, it's not just ForeignKey. Indices are not dropped on other fields too:
$ ./tp3/manage.py sqlmigrate a 0003 BEGIN; -- -- Add field charfield to b -- ALTER TABLE "a_b" ADD COLUMN "charfield" varchar(1) DEFAULT '' NOT NULL; ALTER TABLE "a_b" ALTER COLUMN "charfield" DROP DEFAULT; -- -- Add field intfield to b -- ALTER TABLE "a_b" ADD COLUMN "intfield" integer DEFAULT 0 NOT NULL; ALTER TABLE "a_b" ALTER COLUMN "intfield" DROP DEFAULT; CREATE INDEX "a_b_charfield_a5049317" ON "a_b" ("charfield"); CREATE INDEX "a_b_charfield_a5049317_like" ON "a_b" ("charfield" varchar_pattern_ops); CREATE INDEX "a_b_intfield_b730ef11" ON "a_b" ("intfield"); COMMIT;
$ ./tp3/manage.py sqlmigrate a 0004 BEGIN; -- -- Alter field charfield on b -- -- -- Alter field intfield on b -- COMMIT;
comment:4 by , 7 years ago
Description: | modified (diff) |
---|---|
Summary: | Setting db_index=False on a ForeignKey doesn't actually remove the index → Setting db_index=False on a field doesn't actually remove the index |
Note:
See TracTickets
for help on using tickets.
A tiny test project: https://github.com/craigds/django-28339-testproject
Output with that project: