Django South migration error "contains null values" with null = True field

When adding fields for simple model sketches

easy_thumbnail = ThumbnailerImageField(
    null=True, blank=True, verbose_name=_("Easy_Thumbnails"),
    upload_to="easy_thumbnails",
    resize_source=dict(size=(100, 100), crop="smart"),
)

When executed, the ./manage.py schemamigration test --autosouth performs the following migration:

def forwards(self, orm):
    # Adding field 'Test.easy_thumbnail'
    db.add_column('test_test', 'easy_thumbnail', self.gf('django.db.models.fields.files.ImageField')(), keep_default=False)
[...]
models = {
    'test.test': {
        'Meta': {'object_name': 'Test'},
        'easy_thumbnail': ('django.db.models.fields.files.ImageField', [], {}),

On execution, ./manage.py migrate testI received this error:

The error is `django.db.utils.IntegrityError: column "easy_thumbnail" contains null values`
+3
source share
1 answer

Changing the migration script as follows solves the problem:

  • Adding "null = True, blank = True" to db.add_column
  • Adding '' null ':' True ',' blank ':' True '' in models ['test.test'] ['easy_thumbnail']

The code:

def forwards(self, orm):
    # Adding field 'Test.easy_thumbnail'
    db.add_column('test_test', 'easy_thumbnail', self.gf('django.db.models.fields.files.ImageField')(null=True, blank=True), keep_default=False)
[...]
models = {
    'test.test': {
        'Meta': {'object_name': 'Test'},
        'easy_thumbnail': ('django.db.models.fields.files.ImageField', [], {'null': 'True', 'blank': 'True'}),
+2
source

Source: https://habr.com/ru/post/1768970/


All Articles