I am trying to store a urandom value into the mySQL Database of my Django project. The value must be totally random for cryptography purposes.
I am trying for hours and I am really frustrated. I googled some answers but the solutions wont work.
If I try this as here suggested Store os.urandom variable to Sqlite database in Django
def createkey():
random_bytes = urandom(16)
return b64encode(random_bytes)
key = models.BinaryField(max_length=16, default=createkey)
... i get this error message
django.db.utils.OperationalError: (1067, "Invalid default value for 'key'")
I also tried it with the binascii library os.urandom() decoding Issue like this
def createkey():
return binascii.hexlify(urandom(16)).decode()
With that above i get this error message:
string argument without an encoding
I am using Python 3.6, Django 1.11.5 and a MySQL Database.
Is there any way to store the value of urandom into a Django Model? I would like to store it in a CharField but I am also glad if it works with other Fields.