1 from django.core.management.base import BaseCommand
2 from django.core.management.color import no_style
3 from django.conf import settings
4 from django.db import models
5 from optparse import make_option
6 from south import migration
9 class Command(BaseCommand):
10 option_list = BaseCommand.option_list + (
11 make_option('--skip', action='store_true', dest='skip', default=False,
12 help='Will skip over out-of-order missing migrations'),
13 make_option('--merge', action='store_true', dest='merge', default=False,
14 help='Will run out-of-order missing migrations as they are - no rollbacks.'),
15 make_option('--only', action='store_true', dest='only', default=False,
16 help='Only runs or rolls back the migration specified, and none around it.'),
17 make_option('--fake', action='store_true', dest='fake', default=False,
18 help="Pretends to do the migrations, but doesn't actually execute them."),
20 help = "Runs migrations for all apps."
22 def handle(self, app=None, target=None, skip=False, merge=False, only=False, backwards=False, fake=False, **options):
24 # Work out what the resolve mode is
25 resolve_mode = merge and "merge" or (skip and "skip" or None)
26 # Turn on db debugging
27 from south.db import db
30 # NOTE: THIS IS DUPLICATED FROM django.core.management.commands.syncdb
31 # This code imports any module named 'management' in INSTALLED_APPS.
32 # The 'management' module is the preferred way of listening to post_syncdb
33 # signals, and since we're sending those out with create_table migrations,
34 # we need apps to behave correctly.
35 for app_name in settings.INSTALLED_APPS:
37 __import__(app_name + '.management', {}, {}, [''])
38 except ImportError, exc:
40 if not msg.startswith('No module named') or 'management' not in msg:
42 # END DJANGO DUPE CODE
46 apps = [migration.get_app(app)]
48 apps = migration.get_migrated_apps()
50 migration.migrate_app(
52 resolve_mode = resolve_mode,