Get the latest tech news
How to Get Foreign Keys Horribly Wrong
Common Pitfalls and Potential Optimizations in Django
In this article, I demonstrate common pitfalls, potential optimizations, and implicit behavior related to foreign keys. The reason you can't un-apply this migration is that the RunSQL command to drop the index did not include an opposite operation. Don't use unique_together, use UniqueConstraint instead Always explicitly set db_index and add a comment Always check the SQL generated by migrations before applying them Provide reverse migration operations whenever possible Use concurrent index operations in busy systems Indexes on foreign keys are used indirectly by deletes Use partial indexes when possible Adjust the order of migration operations to reduce impact on live systems Explicitly state tables to lock when using select_for_update Use no_key=True when selecting a row for update to allow referencing objects to be created
Or read this on Hacker News