Anonymous avatar Anonymous committed cb00e0a

Make syncdb actually work this time! I tested it and everything.

Comments (0)

Files changed (2)

management/commands/syncdb.py

 from django.db.models.loading import cache
 import sys
 
+def get_app_name(app):
+    return '.'.join( app.__name__.split('.')[0:-1] )
+
 class Command(NoArgsCommand):
     option_list = NoArgsCommand.option_list + (
         make_option('--verbosity', action='store', dest='verbosity', default='1',
         apps_needing_sync = []
         apps_migrated = []
         for app in models.get_apps():
-            app_name = '.'.join( app.__name__.split('.')[0:-1] )
+            app_name = get_app_name(app)
             migrations = migration.get_migrations(app)
             if migrations is None:
                 apps_needing_sync.append(app_name)
         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 k in apps_needing_sync
+            if get_app_name(k) in apps_needing_sync
         ])
         syncdb.Command().execute(**options)
         settings.INSTALLED_APPS = old_installed
     for migration in migrations:
         print " > %s" % migration
         klass = get_migration(app_name, migration)
-        klass().forwards()
+        if fake:
+            print "   (faked)"
+        else:
+            klass().forwards()
         # Record us as having done this
         record = MigrationHistory.for_migration(app_name, migration)
         record.applied = datetime.datetime.utcnow()
         if migration not in ignore:
             print " < %s" % migration
             klass = get_migration(app_name, migration)
-            klass().backwards()
+            if fake:
+                print "   (faked)"
+            else:
+                klass().backwards()
             # Record us as having not done this
             record = MigrationHistory.for_migration(app_name, migration)
             record.delete()
 
 
-def migrate_app(migration_module, target_name=None, resolve_mode=None):
+def migrate_app(migration_module, target_name=None, resolve_mode=None, fake=False):
     
     # Work out exactly what we're working on
     app_name = os.path.splitext(migration_module.__name__)[0]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.