Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #3822 -- Changed get_indexes_for_model() in django.core.managem…

…ent to quote index names. Thanks, Robin Breathe

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4835 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 302d183a2f843b6379bd5a936f180d4c5b71a46f 1 parent e2937ef
Adrian Holovaty authored March 27, 2007

Showing 1 changed file with 26 additions and 26 deletions. Show diff stats Hide diff stats

  1. 52  django/core/management.py
52  django/core/management.py
@@ -186,7 +186,7 @@ def _get_sql_model_create(model, known_models=set()):
186 186
                 if f.rel.to in known_models:
187 187
                     field_output.append(style.SQL_KEYWORD('REFERENCES') + ' ' + \
188 188
                         style.SQL_TABLE(backend.quote_name(f.rel.to._meta.db_table)) + ' (' + \
189  
-                        style.SQL_FIELD(backend.quote_name(f.rel.to._meta.get_field(f.rel.field_name).column)) + ')' + 
  189
+                        style.SQL_FIELD(backend.quote_name(f.rel.to._meta.get_field(f.rel.field_name).column)) + ')' +
190 190
                         backend.get_deferrable_sql()
191 191
                     )
192 192
                 else:
@@ -232,7 +232,7 @@ def _get_sql_for_pending_references(model, pending_references):
232 232
                 r_name = '%s_refs_%s_%x' % (r_col, col, abs(hash((r_table, table))))
233 233
                 final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % \
234 234
                     (backend.quote_name(r_table), r_name,
235  
-                    backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col), 
  235
+                    backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col),
236 236
                     backend.get_deferrable_sql()))
237 237
             del pending_references[model]
238 238
     return final_output
@@ -456,7 +456,7 @@ def get_sql_indexes_for_model(model):
456 456
             unique = f.unique and 'UNIQUE ' or ''
457 457
             output.append(
458 458
                 style.SQL_KEYWORD('CREATE %sINDEX' % unique) + ' ' + \
459  
-                style.SQL_TABLE('%s_%s' % (model._meta.db_table, f.column)) + ' ' + \
  459
+                style.SQL_TABLE(backend.quote_name('%s_%s' % (model._meta.db_table, f.column))) + ' ' + \
460 460
                 style.SQL_KEYWORD('ON') + ' ' + \
461 461
                 style.SQL_TABLE(backend.quote_name(model._meta.db_table)) + ' ' + \
462 462
                 "(%s);" % style.SQL_FIELD(backend.quote_name(f.column))
@@ -554,7 +554,7 @@ def syncdb(verbosity=1, interactive=True):
554 554
     # to do at this point.
555 555
     _emit_post_sync_signal(created_models, verbosity, interactive)
556 556
 
557  
-    # Install custom SQL for the app (but only if this 
  557
+    # Install custom SQL for the app (but only if this
558 558
     # is a model we've just created)
559 559
     for app in models.get_apps():
560 560
         for model in models.get_models(app):
@@ -696,7 +696,7 @@ def flush(verbosity=1, interactive=True):
696 696
     from django.conf import settings
697 697
     from django.db import connection, transaction, models
698 698
     from django.dispatch import dispatcher
699  
-    
  699
+
700 700
     disable_termcolors()
701 701
 
702 702
     # First, try validating the models.
@@ -709,7 +709,7 @@ def flush(verbosity=1, interactive=True):
709 709
             __import__(app_name + '.management', {}, {}, [''])
710 710
         except ImportError:
711 711
             pass
712  
-    
  712
+
713 713
     sql_list = get_sql_flush()
714 714
 
715 715
     if interactive:
@@ -743,10 +743,10 @@ def flush(verbosity=1, interactive=True):
743 743
         # applications to respond as if the database had been
744 744
         # sync'd from scratch.
745 745
         _emit_post_sync_signal(models.get_models(), verbosity, interactive)
746  
-        
  746
+
747 747
         # Reinstall the initial_data fixture
748 748
         load_data(['initial_data'], verbosity=verbosity)
749  
-        
  749
+
750 750
     else:
751 751
         print "Flush cancelled."
752 752
 flush.help_doc = "Executes ``sqlflush`` on the current database."
@@ -1325,7 +1325,7 @@ def test(app_labels, verbosity=1):
1325 1325
     failures = test_runner(app_list, verbosity)
1326 1326
     if failures:
1327 1327
         sys.exit(failures)
1328  
-        
  1328
+
1329 1329
 test.help_doc = 'Runs the test suite for the specified applications, or the entire site if no apps are specified'
1330 1330
 test.args = '[--verbosity] ' + APP_ARGS
1331 1331
 
@@ -1336,23 +1336,23 @@ def load_data(fixture_labels, verbosity=1):
1336 1336
     from django.db import connection, transaction
1337 1337
     from django.conf import settings
1338 1338
     import sys
1339  
-     
  1339
+
1340 1340
     # Keep a count of the installed objects and fixtures
1341 1341
     count = [0,0]
1342  
-    
  1342
+
1343 1343
     humanize = lambda dirname: dirname and "'%s'" % dirname or 'absolute path'
1344 1344
 
1345 1345
     # Get a cursor (even though we don't need one yet). This has
1346  
-    # the side effect of initializing the test database (if 
  1346
+    # the side effect of initializing the test database (if
1347 1347
     # it isn't already initialized).
1348 1348
     cursor = connection.cursor()
1349  
-    
1350  
-    # Start transaction management. All fixtures are installed in a 
  1349
+
  1350
+    # Start transaction management. All fixtures are installed in a
1351 1351
     # single transaction to ensure that all references are resolved.
1352 1352
     transaction.commit_unless_managed()
1353 1353
     transaction.enter_transaction_management()
1354 1354
     transaction.managed(True)
1355  
-    
  1355
+
1356 1356
     app_fixtures = [os.path.join(os.path.dirname(app.__file__),'fixtures') for app in get_apps()]
1357 1357
     for fixture_label in fixture_labels:
1358 1358
         parts = fixture_label.split('.')
@@ -1365,13 +1365,13 @@ def load_data(fixture_labels, verbosity=1):
1365 1365
                 formats = [format]
1366 1366
             else:
1367 1367
                 formats = []
1368  
-                
  1368
+
1369 1369
         if verbosity > 0:
1370 1370
             if formats:
1371 1371
                 print "Loading '%s' fixtures..." % fixture_name
1372 1372
             else:
1373 1373
                 print "Skipping fixture '%s': %s is not a known serialization format" % (fixture_name, format)
1374  
-            
  1374
+
1375 1375
         for fixture_dir in app_fixtures + list(settings.FIXTURE_DIRS) + ['']:
1376 1376
             if verbosity > 1:
1377 1377
                 print "Checking %s for fixtures..." % humanize(fixture_dir)
@@ -1387,7 +1387,7 @@ def load_data(fixture_labels, verbosity=1):
1387 1387
                     fixture = open(full_path, 'r')
1388 1388
                     if label_found:
1389 1389
                         fixture.close()
1390  
-                        print style.ERROR("Multiple fixtures named '%s' in %s. Aborting." % 
  1390
+                        print style.ERROR("Multiple fixtures named '%s' in %s. Aborting." %
1391 1391
                             (fixture_name, humanize(fixture_dir)))
1392 1392
                         transaction.rollback()
1393 1393
                         transaction.leave_transaction_management()
@@ -1406,7 +1406,7 @@ def load_data(fixture_labels, verbosity=1):
1406 1406
                         except Exception, e:
1407 1407
                             fixture.close()
1408 1408
                             sys.stderr.write(
1409  
-                                style.ERROR("Problem installing fixture '%s': %s\n" % 
  1409
+                                style.ERROR("Problem installing fixture '%s': %s\n" %
1410 1410
                                      (full_path, str(e))))
1411 1411
                             transaction.rollback()
1412 1412
                             transaction.leave_transaction_management()
@@ -1424,27 +1424,27 @@ def load_data(fixture_labels, verbosity=1):
1424 1424
             print "Installed %d object(s) from %d fixture(s)" % tuple(count)
1425 1425
     transaction.commit()
1426 1426
     transaction.leave_transaction_management()
1427  
-        
  1427
+
1428 1428
 load_data.help_doc = 'Installs the named fixture(s) in the database'
1429 1429
 load_data.args = "[--verbosity] fixture, fixture, ..."
1430  
- 
  1430
+
1431 1431
 def dump_data(app_labels, format='json', indent=None):
1432 1432
     "Output the current contents of the database as a fixture of the given format"
1433 1433
     from django.db.models import get_app, get_apps, get_models
1434 1434
     from django.core import serializers
1435  
- 
  1435
+
1436 1436
     if len(app_labels) == 0:
1437 1437
         app_list = get_apps()
1438 1438
     else:
1439 1439
         app_list = [get_app(app_label) for app_label in app_labels]
1440  
- 
  1440
+
1441 1441
     # Check that the serialization format exists; this is a shortcut to
1442 1442
     # avoid collating all the objects and _then_ failing.
1443 1443
     try:
1444 1444
         serializers.get_serializer(format)
1445 1445
     except KeyError:
1446  
-        sys.stderr.write(style.ERROR("Unknown serialization format: %s\n" % format))        
1447  
-    
  1446
+        sys.stderr.write(style.ERROR("Unknown serialization format: %s\n" % format))
  1447
+
1448 1448
     objects = []
1449 1449
     for app in app_list:
1450 1450
         for model in get_models(app):
@@ -1539,7 +1539,7 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
1539 1539
     parser.add_option('--noreload', action='store_false', dest='use_reloader', default=True,
1540 1540
         help='Tells Django to NOT use the auto-reloader when running the development server.')
1541 1541
     parser.add_option('--format', default='json', dest='format',
1542  
-        help='Specifies the output serialization format for fixtures')    
  1542
+        help='Specifies the output serialization format for fixtures')
1543 1543
     parser.add_option('--indent', default=None, dest='indent',
1544 1544
         type='int', help='Specifies the indent level to use when pretty-printing output')
1545 1545
     parser.add_option('--verbosity', action='store', dest='verbosity', default='1',

0 notes on commit 302d183

Please sign in to comment.
Something went wrong with that request. Please try again.