Andrew Godwin committed f7a9918

Add --all option to syncdb so you can syncdb migrated apps if you suddenly fall mentally ill :) (#170)

  • Participants
  • Parent commits b881df2

Comments (0)

Files changed (1)


             help='Tells Django to NOT prompt the user for input of any kind.'),
         make_option('--migrate', action='store_true', dest='migrate', default=False,
             help='Tells South to also perform migrations after the sync. Default for during testing, and other internal calls.'),
+        make_option('--all', action='store_true', dest='migrate_all', default=False,
+            help='Makes syncdb work on all apps, even migrated ones. Be careful!'),
     if '--verbosity' not in [opt.get_opt_string() for opt in BaseCommand.option_list]:
         option_list += (
     help = "Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created, except those which use migrations."
-    def handle_noargs(self, **options):
+    def handle_noargs(self, migrate_all=False, **options):
         # Work out what uses migrations and so doesn't need syncing
         apps_needing_sync = []
         apps_migrated = []
         for app in models.get_apps():
             app_name = get_app_name(app)
             migrations = migration.get_app(app)
-            if migrations is None:
+            if migrations is None or migrate_all:
                 # This is a migrated app, leave it
         verbosity = int(options.get('verbosity', 0))
         # Run syncdb on only the ones needed
         if verbosity:
             print "Syncing..."
         old_installed, settings.INSTALLED_APPS = settings.INSTALLED_APPS, apps_needing_sync
         old_app_store, cache.app_store = cache.app_store, SortedDict([
             (k, v) for (k, v) in cache.app_store.items()
             if get_app_name(k) in apps_needing_sync
         # This will allow the setting of the MySQL storage engine, for example.
         # OK, run the actual syncdb
         settings.INSTALLED_APPS = old_installed
         cache.app_store = old_app_store
         # Migrate if needed
         if options.get('migrate', True):
             if verbosity:
                 print "Migrating..."
             management.call_command('migrate', **options)
         # Be obvious about what we did
         if verbosity:
             print "\nSynced:\n > %s" % "\n > ".join(apps_needing_sync)