views:

24

answers:

1

When adding a field for easy-thumbnails to a model

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

When executing ./manage.py schemamigration test --auto, South produces 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', [], {}),

When executing ./manage.py migrate test, I got this error:

The error is `django.db.utils.IntegrityError: column "easy_thumbnail" contains null values`
A: 

Modifying the migration script as follows solves the problem:

  • Adding "null=True, blank=True" in 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'}),
Pascal Polleunus
This is first step. In second step. You should set old data to sensible defaults and in third step, remove the null values...if this is what make sense in Your application, of course.
Almad
What matters here is that south doesn't define the new column with allowing null and blank as defined in the model.
Pascal Polleunus