I came across the same problem. Since I did not find a way to do tests for datamigrations, I used assertions to detect corrupted data:
from django.conf import settings class MyModel(models.Model): stupid_error = models.BooleanField(default=False) def __init__(self, *args, **kwargs): super(MyModel, self).__init__(*args, **kwargs) if settings.DEBUG: assert not self.stupid_error
Well, thatβs a little awkward. But it seems to work.
[Edit] Once again thinking about this, I found a much better solution: put the tests in DataMigration itself. Since the transition is a one-time code, it does not need to be tested again and again.
class Migration(DataMigration): def forwards(self, orm):
source share