Make the deletion of stale content types safer
|Reported by:||aaugustin||Owned by:||speijnik|
|Cc:||charette.s@…, speijnik||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||yes||Patch needs improvement:||yes|
When a model is removed, syncdb offers to remove its content type :
The following content types are stale and need to be deleted: myapp | mymodel Any objects related to these content types by a foreign key will also be deleted. Are you sure you want to delete these content types? If you're unsure, answer 'no'. Type 'yes' to continue, or 'no' to cancel:
While perfectly clear, this text is quite unhelpful, because there's no easy way to determine if any instance still has a foreign key to the content type.
To mitigate the risk of accidental cascade deletions -- sometimes you can be sure and wrong -- Django could tell the user how many related objects will be deleted, if any. This is similar to the admin's cascade delete UI, but only one level deep.
It would be quite embarrassing to admit why I'm filing this ticket. Let's just say the problem that shows up in the real world. Until we do something about this, I'll add on_delete=models.PROTECT to all my foreign key to ContentType in GenericForeignKey definitions.
Change History (11)
comment:5 Changed 13 months ago by speijnik
- Owner changed from nobody to speijnik
- Status changed from new to assigned
Changed 13 months ago by speijnik
comment:9 Changed 13 months ago by slurms
- Needs documentation set
- Needs tests set
- Patch needs improvement set