foundertherapy / django-cryptographic-fields

A set of fields that wrap standard Django fields with encryption provided by the python cryptography library.
MIT License
29 stars 34 forks source link

"FIELD_ENCRYPTION_KEY must be defined in settings" - but it is defined in settings #27

Open Jessica-Ryan opened 2 years ago

Jessica-Ryan commented 2 years ago

I am using encrypted_model_fields to encrypt a model field. The field I am encrypting is a password used to access a user account for another app via an api.

According to the docs I need to import the module and then wrap the model field as follows:

Models.py

from encrypted_model_fields.fields import EncryptedCharField
account_password = EncryptedCharField(models.CharField(max_length=20, blank=True))

In addition to that I need to add a FIELD_ENCRYPTION_KEY to settings.py, which I have done, as per the docs.

Settings.py

FIELD_ENCRYPTION_KEY = os.environ.get('FIELD_ENCRYPTION_KEY')

I have also added 'encrypted_model_fields' to installed apps in settings.py and the encryption key to .env, which is in place of the placeholder below..env:

export FIELD_ENCRYPTION_KEY=my_encryption_key_place_holder

When I run makemigrations I receive the following error:

django.core.exceptions.ImproperlyConfigured: FIELD_ENCRYPTION_KEY must be defined in settings

I have defined it - so why is it not found?

BrandenLY commented 2 years ago

Hi, Jessica!

I'm not sure if you've resolved your issue or not yet, however you may find this documentation helpful.

Django Encrypted Model Fields Documentation

If this does not help address your issues, it may be helpful to include what you have in your settings.py file, as well as in your models.py file where you are attempting to use encrypted fields.