Error "reset"ing app with self-referencing ForeignKey
|Reported by:||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||no|
I am trying to define a foreign key relating a model to itself, to create a tree structure, ie
parent = ForeignKey("Category")
"python manage.py reset <app>" fails with the error:
ERROR: constraint "parent_id_referencing_event_category_id" does not exist
ALTER TABLE "event_category" DROP CONSTRAINT "parent_id_referencing_event_category_id";
I am using PostgreSQL.
A similar error occurs for some ForeignKey relations, but not others. It seems to happen whenever the SQL for the reset command includes an "ALTER TABLE ... DROP CONSTRAINT" command. This command is sometimes included and sometimes not.