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

Migrations generating duplicates in Django 1.11 #7

Closed jammons closed 6 years ago

jammons commented 6 years ago

I'm using this library for a single field as such:

class Account(models.Model):
    address = models.EmailField(blank=True)
    password = encrypt(models.CharField(max_length=128, blank=True))

When I run ./manage.py makemigrations, it generates a new migration for this model, even though I've already generated and ran the migration for this model.

 ./manage.py makemigrations
Migrations for 'accounts':
  audit/accounts/migrations/0007_auto_20171016_2125.py
    - Alter field password on account
 ./manage.py makemigrations
Migrations for 'accounts':
  audit/accounts/migrations/0008_auto_20171016_2128.py
    - Alter field password on account
 ./manage.py makemigrations
Migrations for 'accounts':
  audit/accounts/migrations/0009_auto_20171016_2128.py
    - Alter field password on account

Each migration contains the same content:

# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-16 21:25
from __future__ import unicode_literals

from django.db import migrations, models
import django_cryptography.fields

class Migration(migrations.Migration):

    dependencies = [
        ('accounts', '0006_auto_20171014_0122'),
    ]

    operations = [
        migrations.AlterField(
            model_name='account',
            name='password',
            field=django_cryptography.fields.encrypt(models.CharField(verbose_name=models.CharField(verbose_name=models.CharField(blank=True, max_length=128)))),
        ),
    ]

Any idea what might be up here and how to solve it?

georgemarshall commented 6 years ago

I do not have an immediate answer on this, but I will be investigating it and creating test cases. I updated the test harness to reflect the current releases for Django.

jammons commented 6 years ago

Awesome, thank you for looking into it.

karimamer commented 6 years ago

I am looking into this today

georgemarshall commented 6 years ago

@jammons I cut a pre-release version, so feel free to try it out. If there are no further issues I will cut a final release. pip install --pre django-cryptography

https://pypi.org/project/django-cryptography/0.3b1/

jammons commented 6 years ago

Ok cool. I installed the --pre version, ran migrations once and it create a migration, then ran it a few more times and it didn't, so it looks like the fix works. Thanks @karimamer and @georgemarshall for getting that working.