divio/django-cms — Issue #1192: Cannot migrate cms backwards [at least in SQLite]
Author: kezabelle
Created: 2012-03-09 20:58:52+00:00
State: open

```
./manage.py migrate cms

[... does lots of output ...]

$ ./manage.py migrate cms zero
Running migrations for cms:
- Migrating backwards to zero state.

[... does lots of output ...]

Traceback (most recent call last):
File "manage.py", line 11, in
execute_manager(settings)
File "/path/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/path/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/path/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/path/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/path/south/management/commands/migrate.py", line 105, in handle
ignore_ghosts = ignore_ghosts,
File "/path/south/migration/__init__.py", line 191, in migrate_app
success = migrator.migrate_many(target, workplan, database)
File "/path/south/migration/migrators.py", line 221, in migrate_many
result = migrator.__class__.migrate_many(migrator, target, migrations, database)
File "/path/south/migration/migrators.py", line 338, in migrate_many
self.migrate(migration, database)
File "/path/south/migration/migrators.py", line 125, in migrate
result = self.run(migration)
File "/path/south/migration/migrators.py", line 99, in run
return self.run_migration(migration)
File "/path/south/migration/migrators.py", line 81, in run_migration
migration_function()
File "/path/south/migration/migrators.py", line 57, in
return (lambda: direction(orm))
File "/path/cms/migrations/0026_finish_placeholder_migration.py", line 30, in backwards
db.add_column('cms_cmsplugin', 'placeholder', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['cms.CMSPlugin']))
File "/path/south/db/sqlite3.py", line 29, in add_column
raise ValueError("You cannot add a null=False column without a default value.")
ValueError: You cannot add a null=False column without a default value.
```

I can't tell, from the resolution of #213, whether this would come under the same '3rd party issue' wontfix. The same migration (0026) has been _fixed_ before, in #435. I've no idea if it affects other database backends, though it seems like it could.

The fix seems simple: [line 27](https://github.com/divio/django-cms/blob/develop/cms/migrations/0026_finish_placeholder_migration.py#L27) would have the same problem, were it not for having ```default=0```, which could probably be applied to [line 30](https://github.com/divio/django-cms/blob/develop/cms/migrations/0026_finish_placeholder_migration.py#L30) too?

Relevant settings
============

```
$ ./manage.py diffsettings
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/path/to/testdb.sqlite3'
}
}
CMS_FRONTEND_LANGUAGES = ['en'] ###
CMS_LANGUAGES = (('en', 'English'),) ###
CMS_LANGUAGE_FALLBACK = False ###
CMS_MODERATOR = False ###
CMS_PERMISSION = False ###
CMS_TEMPLATES = (('base.html', 'Default'),) ###
INSTALLED_APPS = ['django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages',
'django.contrib.admin', 'django.contrib.admindocs', 'cms', 'menus', 'mptt',
'south', 'sekizai',]

>>> import cms, django
>>> cms.__version__
'2.2' # Actually develop
>>> django.VERSION
(1, 3, 1, 'final', 0)
>>>
```