georgemarshall / django-cryptography

Easily encrypt data in Django
https://django-cryptography.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
379 stars 75 forks source link

Migrate existing database #11

Closed Watchwolf closed 4 years ago

Watchwolf commented 6 years ago

Hello,

Have you an idea how I can migrate an existing database in order to user django-cryptography ?

I am planning to use it in a existing database. Currently the migration only convert charfield to blob but do not encrypt the data.

I am searching to do it manually but right now I do not have a solution.

georgemarshall commented 6 years ago

I have an example of this in the test cases, check it out at https://github.com/georgemarshall/django-cryptography/tree/master/tests/fields/test_migrations_normal_to_encrypted, hopefully that helps.

TheBlusky commented 6 years ago

Facing the same issue here. Did you manage to do it ?

Julioocz commented 6 years ago

Follow django fernet procedure. It worked for me https://django-fernet-fields.readthedocs.io/en/latest/#migrations

thismatters commented 6 years ago

Here is the migration template I cooked up for doing exactly this: https://gist.github.com/thismatters/53787f2d021fa5a1df640cd7b98d1185

If I find the time I'll make a django command to automatically produce these migrations.

NOTE: This didn't actually work when running against PostresSQL, I had to split up the data migrations and the table alterations into separate migration files.

georgemarshall commented 4 years ago

Documentation has been added to cover this.

https://django-cryptography.readthedocs.io/en/latest/migrating.html