Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

magic-removal: Fixed #1082 -- Added a 'supports_constraints' variable…

… for each database backend, and set SQLite's to False

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1757 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2d4acdc2784c7a6e65294b04a0e2fb3762947735 1 parent aa9fa34
Adrian Holovaty authored December 21, 2005
25  django/core/management.py
@@ -117,18 +117,19 @@ def get_sql_create(app):
117 117
 
118 118
         # Take care of any ALTER TABLE statements to add constraints
119 119
         # after the fact.
120  
-        if klass in pending_references:
121  
-            for rel_class, f in pending_references[klass]:
122  
-                rel_opts = rel_class._meta
123  
-                r_table = rel_opts.db_table
124  
-                r_col = f.column
125  
-                table = opts.db_table
126  
-                col = opts.get_field(f.rel.field_name).column
127  
-                final_output.append('ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \
128  
-                    (backend.quote_name(r_table),
129  
-                    backend.quote_name("%s_referencing_%s_%s" % (r_col, table, col)),
130  
-                    backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col)))
131  
-            del pending_references[klass]
  120
+        if backend.supports_constraints:
  121
+            if klass in pending_references:
  122
+                for rel_class, f in pending_references[klass]:
  123
+                    rel_opts = rel_class._meta
  124
+                    r_table = rel_opts.db_table
  125
+                    r_col = f.column
  126
+                    table = opts.db_table
  127
+                    col = opts.get_field(f.rel.field_name).column
  128
+                    final_output.append('ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \
  129
+                        (backend.quote_name(r_table),
  130
+                        backend.quote_name("%s_referencing_%s_%s" % (r_col, table, col)),
  131
+                        backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col)))
  132
+                del pending_references[klass]
132 133
 
133 134
         # Keep track of the fact that we've created the table for this model.
134 135
         models_output.add(klass)
2  django/db/backends/ado_mssql/base.py
@@ -76,6 +76,8 @@ def close(self):
76 76
             self.connection.close()
77 77
             self.connection = None
78 78
 
  79
+supports_constraints = True
  80
+
79 81
 def quote_name(name):
80 82
     if name.startswith('[') and name.endswith(']'):
81 83
         return name # Quoting once is enough.
2  django/db/backends/mysql/base.py
@@ -83,6 +83,8 @@ def close(self):
83 83
             self.connection.close()
84 84
             self.connection = None
85 85
 
  86
+supports_constraints = True
  87
+
86 88
 def quote_name(name):
87 89
     if name.startswith("`") and name.endswith("`"):
88 90
         return name # Quoting once is enough.
2  django/db/backends/postgresql/base.py
@@ -49,6 +49,8 @@ def close(self):
49 49
             self.connection.close()
50 50
             self.connection = None
51 51
 
  52
+supports_constraints = True
  53
+
52 54
 def quote_name(name):
53 55
     if name.startswith('"') and name.endswith('"'):
54 56
         return name # Quoting once is enough.
2  django/db/backends/sqlite3/base.py
@@ -70,6 +70,8 @@ def convert_query(self, query, num_params):
70 70
         # XXX this seems too simple to be correct... is this right?
71 71
         return query % tuple("?" * num_params)
72 72
 
  73
+supports_constraints = False
  74
+
73 75
 def quote_name(name):
74 76
     if name.startswith('"') and name.endswith('"'):
75 77
         return name # Quoting once is enough.

0 notes on commit 2d4acdc

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