diff options
| author | Helen ST <helenst@gmail.com> | 2013-09-23 15:00:46 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-09-23 11:51:58 -0400 |
| commit | 41167645b1039067127fa215d4d28296bfa4cfdc (patch) | |
| tree | f031af72fab8f12416e4a226ab8ef14685b708b0 /tests | |
| parent | a53caf28bf2ab29cf4e78a968b3887ddb6d6e83d (diff) | |
Fixed #14028 - Added validation for clashing db_columns.
Thanks akaariai for the suggestion.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/invalid_models/invalid_models/models.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/invalid_models/invalid_models/models.py b/tests/invalid_models/invalid_models/models.py index 66ce5c4c61..1113c0c056 100644 --- a/tests/invalid_models/invalid_models/models.py +++ b/tests/invalid_models/invalid_models/models.py @@ -364,6 +364,56 @@ class BadIndexTogether1(models.Model): ] +class DuplicateColumnNameModel1(models.Model): + """ + A field (bar) attempts to use a column name which is already auto-assigned + earlier in the class. This should raise a validation error. + """ + foo = models.IntegerField() + bar = models.IntegerField(db_column='foo') + + class Meta: + db_table = 'foobar' + + +class DuplicateColumnNameModel2(models.Model): + """ + A field (foo) attempts to use a column name which is already auto-assigned + later in the class. This should raise a validation error. + """ + foo = models.IntegerField(db_column='bar') + bar = models.IntegerField() + + class Meta: + db_table = 'foobar' + + +class DuplicateColumnNameModel3(models.Model): + """Two fields attempt to use each others' names. + + This is not a desirable scenario but valid nonetheless. + + It should not raise a validation error. + """ + foo = models.IntegerField(db_column='bar') + bar = models.IntegerField(db_column='foo') + + class Meta: + db_table = 'foobar3' + + +class DuplicateColumnNameModel4(models.Model): + """Two fields attempt to use the same db_column value. + + This should raise a validation error. + """ + foo = models.IntegerField(db_column='baz') + bar = models.IntegerField(db_column='baz') + + class Meta: + db_table = 'foobar' + + model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute that is a positive integer. invalid_models.fielderrors: "charfield2": CharFields require a "max_length" attribute that is a positive integer. invalid_models.fielderrors: "charfield3": CharFields require a "max_length" attribute that is a positive integer. @@ -477,6 +527,9 @@ invalid_models.hardreferencemodel: 'm2m_4' defines a relation with the model 'in invalid_models.badswappablevalue: TEST_SWAPPED_MODEL_BAD_VALUE is not of the form 'app_label.app_name'. invalid_models.badswappablemodel: Model has been swapped out for 'not_an_app.Target' which has not been installed or is abstract. invalid_models.badindextogether1: "index_together" refers to field_that_does_not_exist, a field that doesn't exist. +invalid_models.duplicatecolumnnamemodel1: Field 'bar' has column name 'foo' that is already used. +invalid_models.duplicatecolumnnamemodel2: Field 'bar' has column name 'bar' that is already used. +invalid_models.duplicatecolumnnamemodel4: Field 'bar' has column name 'baz' that is already used. """ if not connection.features.interprets_empty_strings_as_nulls: |
