incuna / django-pgcrypto-fields

Transparent field level encryption for Django using the pgcrypto postgresql extension.
BSD 2-Clause "Simplified" License
231 stars 51 forks source link

Adding default value to IntegerField in subsequent migrations throws an error #298

Closed vlad-kiratech closed 3 years ago

vlad-kiratech commented 3 years ago

The issue is described in this SO topic. Looks like it has existed for over a year. I ran into it today, and seting null=True doesn't actually help. Any ideas if it has ever been resolved?

peterfarrell commented 3 years ago

We don't have support for migration changes that involve setting defaults other then Null. Bytea is the datatype used for the encryption at the Postgres level. Setting a default of 0 in the migration will not work because the default is not encrypted. There is no such thing as a default for bytea -- it just sorta works at the Django level because the default of 0 when an object is created gets encrypted. A PR is welcome to solve this issue.

peterfarrell commented 3 years ago

@vlad-kiratech See:

https://github.com/incuna/django-pgcrypto-fields#migrating-existing-fields-into-pgcrypto-fields

This same thing applies to adding a new default in a migration.