Django doesn't come with a solution to encrypt database data out-of-the-box. While community projects exist, they often require complex migration processes or double-writing to new columns. At Sentry, for our high-traffic distributed system, we needed a solution that would abstract encryption logic without worrying about encryption keys on a case-by-case basis or performing risky migrations on millions of existing entries.
We built EncryptedFields, a custom Field base class that provides drop-in, no database migration, replacements for CharField, JSONField, and TextField. Our approach allows for a "hybrid" state: the field handles both old plain-text formats and the new encrypted format on-the-fly. This eliminated the need for complex data migrations or secondary columns, making the transition safe and seamless for our engineers.