diff -urN django-0.9.6/core/management.py django/core/management.py
old
|
new
|
|
206 | 206 | for i, line in enumerate(table_output): # Combine and add commas. |
207 | 207 | full_statement.append(' %s%s' % (line, i < len(table_output)-1 and ',' or '')) |
208 | 208 | full_statement.append(');') |
209 | | final_output.append('\n'.join(full_statement)) |
| 209 | if opts.sql_generation_required: |
| 210 | final_output.append('\n'.join(full_statement)) |
210 | 211 | |
211 | 212 | return final_output, pending_references |
212 | 213 | |
… |
… |
|
230 | 231 | # For MySQL, r_name must be unique in the first 64 characters. |
231 | 232 | # So we are careful with character usage here. |
232 | 233 | r_name = '%s_refs_%s_%x' % (r_col, col, abs(hash((r_table, table)))) |
233 | | final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % \ |
234 | | (backend.quote_name(r_table), r_name, |
235 | | backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col), |
236 | | backend.get_deferrable_sql())) |
| 234 | if rel_opts.sql_generation_required: |
| 235 | final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % \ |
| 236 | (backend.quote_name(r_table), r_name, |
| 237 | backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col), |
| 238 | backend.get_deferrable_sql())) |
237 | 239 | del pending_references[model] |
238 | 240 | return final_output |
239 | 241 | |
… |
… |
|
312 | 314 | for model in app_models: |
313 | 315 | if cursor and model._meta.db_table in table_names: |
314 | 316 | # Drop the table now |
315 | | output.append('%s %s;' % (style.SQL_KEYWORD('DROP TABLE'), |
316 | | style.SQL_TABLE(backend.quote_name(model._meta.db_table)))) |
| 317 | if model._meta.sql_generation_required: |
| 318 | output.append('%s %s;' % (style.SQL_KEYWORD('DROP TABLE'), |
| 319 | style.SQL_TABLE(backend.quote_name(model._meta.db_table)))) |
317 | 320 | if backend.supports_constraints and references_to_delete.has_key(model): |
318 | 321 | for rel_class, f in references_to_delete[model]: |
319 | 322 | table = rel_class._meta.db_table |
320 | 323 | col = f.column |
321 | 324 | r_table = model._meta.db_table |
322 | 325 | r_col = model._meta.get_field(f.rel.field_name).column |
323 | | output.append('%s %s %s %s;' % \ |
324 | | (style.SQL_KEYWORD('ALTER TABLE'), |
325 | | style.SQL_TABLE(backend.quote_name(table)), |
326 | | style.SQL_KEYWORD(backend.get_drop_foreignkey_sql()), |
327 | | style.SQL_FIELD(backend.quote_name('%s_refs_%s_%x' % (col, r_col, abs(hash((table, r_table)))))))) |
| 326 | if rel_class._meta.sql_generation_required: |
| 327 | output.append('%s %s %s %s;' % \ |
| 328 | (style.SQL_KEYWORD('ALTER TABLE'), |
| 329 | style.SQL_TABLE(backend.quote_name(table)), |
| 330 | style.SQL_KEYWORD(backend.get_drop_foreignkey_sql()), |
| 331 | style.SQL_FIELD(backend.quote_name('%s_refs_%s_%x' % (col, r_col, abs(hash((table, r_table)))))))) |
328 | 332 | del references_to_delete[model] |
329 | 333 | |
330 | 334 | # Output DROP TABLE statements for many-to-many tables. |
… |
… |
|
451 | 455 | from django.db import backend |
452 | 456 | output = [] |
453 | 457 | |
454 | | for f in model._meta.fields: |
455 | | if f.db_index: |
456 | | unique = f.unique and 'UNIQUE ' or '' |
457 | | output.append( |
458 | | style.SQL_KEYWORD('CREATE %sINDEX' % unique) + ' ' + \ |
459 | | style.SQL_TABLE('%s_%s' % (model._meta.db_table, f.column)) + ' ' + \ |
460 | | style.SQL_KEYWORD('ON') + ' ' + \ |
461 | | style.SQL_TABLE(backend.quote_name(model._meta.db_table)) + ' ' + \ |
462 | | "(%s);" % style.SQL_FIELD(backend.quote_name(f.column)) |
| 458 | if model._meta.sql_generation_required: |
| 459 | for f in model._meta.fields: |
| 460 | if f.db_index: |
| 461 | unique = f.unique and 'UNIQUE ' or '' |
| 462 | output.append( |
| 463 | style.SQL_KEYWORD('CREATE %sINDEX' % unique) + ' ' + \ |
| 464 | style.SQL_TABLE('%s_%s' % (model._meta.db_table, f.column)) + ' ' + \ |
| 465 | style.SQL_KEYWORD('ON') + ' ' + \ |
| 466 | style.SQL_TABLE(backend.quote_name(model._meta.db_table)) + ' ' + \ |
| 467 | "(%s);" % style.SQL_FIELD(backend.quote_name(f.column)) |
463 | 468 | ) |
464 | 469 | return output |
465 | 470 | |
diff -urN django-0.9.6/db/models/options.py django/db/models/options.py
old
|
new
|
|
13 | 13 | |
14 | 14 | DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering', |
15 | 15 | 'unique_together', 'permissions', 'get_latest_by', |
16 | | 'order_with_respect_to', 'app_label') |
| 16 | 'order_with_respect_to', 'app_label', 'sql_generation_required') |
17 | 17 | |
18 | 18 | class Options(object): |
19 | 19 | def __init__(self, meta): |
… |
… |
|
25 | 25 | self.unique_together = [] |
26 | 26 | self.permissions = [] |
27 | 27 | self.object_name, self.app_label = None, None |
| 28 | self.sql_generation_required = True |
28 | 29 | self.get_latest_by = None |
29 | 30 | self.order_with_respect_to = None |
30 | 31 | self.admin = None |
… |
… |
|
88 | 89 | |
89 | 90 | def __repr__(self): |
90 | 91 | return '<Options for %s>' % self.object_name |
91 | | |
| 92 | |
92 | 93 | def __str__(self): |
93 | 94 | return "%s.%s" % (self.app_label, self.module_name) |
94 | | |
| 95 | |
95 | 96 | def get_field(self, name, many_to_many=True): |
96 | 97 | "Returns the requested field by name. Raises FieldDoesNotExist on error." |
97 | 98 | to_search = many_to_many and (self.fields + self.many_to_many) or self.fields |