Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #3779 -- Resolved problem with order of creation of m2m tables …

…during syncdb. Well spotted, Ben Slavin, and thanks for the very helpful test case.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4780 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e21a4c8d016e48fb9935e250fe8908c666fb1bbd 1 parent 6a7a155
Russell Keith-Magee authored March 23, 2007

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

  1. 10  django/core/management.py
10  django/core/management.py
@@ -280,7 +280,7 @@ def get_sql_delete(app):
280 280
     from django.db import backend, connection, models, get_introspection_module
281 281
     introspection = get_introspection_module()
282 282
 
283  
-    # This should work even if a connecton isn't available
  283
+    # This should work even if a connection isn't available
284 284
     try:
285 285
         cursor = connection.cursor()
286 286
     except:
@@ -512,6 +512,7 @@ def syncdb(verbosity=1, interactive=True):
512 512
     created_models = set()
513 513
     pending_references = {}
514 514
 
  515
+    # Create the tables for each model
515 516
     for app in models.get_apps():
516 517
         app_name = app.__name__.split('.')[-2]
517 518
         model_list = models.get_models(app)
@@ -533,6 +534,11 @@ def syncdb(verbosity=1, interactive=True):
533 534
                 cursor.execute(statement)
534 535
             table_list.append(model._meta.db_table)
535 536
 
  537
+    # Create the m2m tables. This must be done after all tables have been created
  538
+    # to ensure that all referred tables will exist.
  539
+    for app in models.get_apps():
  540
+        app_name = app.__name__.split('.')[-2]
  541
+        model_list = models.get_models(app)
536 542
         for model in model_list:
537 543
             if model in created_models:
538 544
                 sql = _get_many_to_many_sql_for_model(model)
@@ -542,7 +548,7 @@ def syncdb(verbosity=1, interactive=True):
542 548
                     for statement in sql:
543 549
                         cursor.execute(statement)
544 550
 
545  
-        transaction.commit_unless_managed()
  551
+    transaction.commit_unless_managed()
546 552
 
547 553
     # Send the post_syncdb signal, so individual apps can do whatever they need
548 554
     # to do at this point.

0 notes on commit e21a4c8

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