diff options
| author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2014-09-16 23:37:18 +0600 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-09-23 10:11:58 -0400 |
| commit | 58d7b84d53832a056128192c335127f10e082f2c (patch) | |
| tree | f74641259801fb44fc367427293d6ca1be2e1032 /tests | |
| parent | 09b5ff64b80b2a31dc32961df16e2d3f4b681235 (diff) | |
[1.7.x] Fixed #23065 -- Quoted constraint names in SQL generated by migrations.
Backport of 83cd18633f from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/schema/tests.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py index c51ef97106..02207ff6e9 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -1040,3 +1040,53 @@ class SchemaTests(TransactionTestCase): DatabaseError, lambda: list(Thing.objects.all()), ) + + @unittest.skipUnless(connection.features.supports_foreign_keys, "No FK support") + def test_remove_constraints_capital_letters(self): + """ + #23065 - Constraint names must be quoted if they contain capital letters. + """ + def get_field(*args, **kwargs): + kwargs['db_column'] = "CamelCase" + field = kwargs.pop('field_class', IntegerField)(*args, **kwargs) + field.set_attributes_from_name("CamelCase") + return field + + model = Author + field = get_field() + table = model._meta.db_table + column = field.column + + with connection.schema_editor() as editor: + editor.create_model(model) + editor.add_field(model, field) + + editor.execute( + editor.sql_create_index % { + "table": editor.quote_name(table), + "name": editor.quote_name("CamelCaseIndex"), + "columns": editor.quote_name(column), + "extra": "", + } + ) + editor.alter_field(model, get_field(db_index=True), field) + + editor.execute( + editor.sql_create_unique % { + "table": editor.quote_name(table), + "name": editor.quote_name("CamelCaseUniqConstraint"), + "columns": editor.quote_name(field.column), + } + ) + editor.alter_field(model, get_field(unique=True), field) + + editor.execute( + editor.sql_create_fk % { + "table": editor.quote_name(table), + "name": editor.quote_name("CamelCaseFKConstraint"), + "column": editor.quote_name(column), + "to_table": editor.quote_name(table), + "to_column": editor.quote_name(model._meta.auto_field.column), + } + ) + editor.alter_field(model, get_field(Author, field_class=ForeignKey), field) |
