diff options
author | Scott <13770321+scott-8@users.noreply.github.com> | 2022-04-16 13:29:51 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-16 15:29:51 +0200 |
commit | e12670016bbcebcc0d89c2ac4a0121951181fbae (patch) | |
tree | 2f700f2b46bf13e3d7a7afdd336e2dfa5e6d4dd9 /tests/inspectdb | |
parent | a1e4e86f923dc8387b0a9c3025bdd5d096a6ebb8 (diff) | |
download | django-e12670016bbcebcc0d89c2ac4a0121951181fbae.tar.gz |
Fixed #33643 -- Fixed inspectdb crash on functional unique constraints on Oracle.
Diffstat (limited to 'tests/inspectdb')
-rw-r--r-- | tests/inspectdb/models.py | 14 | ||||
-rw-r--r-- | tests/inspectdb/tests.py | 7 |
2 files changed, 21 insertions, 0 deletions
diff --git a/tests/inspectdb/models.py b/tests/inspectdb/models.py index f2c23f0e0c..4227299b94 100644 --- a/tests/inspectdb/models.py +++ b/tests/inspectdb/models.py @@ -1,4 +1,5 @@ from django.db import connection, models +from django.db.models.functions import Lower class People(models.Model): @@ -117,3 +118,16 @@ class UniqueTogether(models.Model): ("from_field", "field1"), ("non_unique", "non_unique_0"), ] + + +class FuncUniqueConstraint(models.Model): + name = models.CharField(max_length=255) + rank = models.IntegerField() + + class Meta: + constraints = [ + models.UniqueConstraint( + Lower("name"), models.F("rank"), name="index_lower_name" + ) + ] + required_db_features = {"supports_expression_indexes"} diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index 53c7ce9013..39d5b6cbe5 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -330,6 +330,13 @@ class InspectDBTestCase(TestCase): output = out.getvalue() self.assertIn("class InspectdbSpecialTableName(models.Model):", output) + @skipUnlessDBFeature("supports_expression_indexes") + def test_table_with_func_unique_constraint(self): + out = StringIO() + call_command("inspectdb", "inspectdb_funcuniqueconstraint", stdout=out) + output = out.getvalue() + self.assertIn("class InspectdbFuncuniqueconstraint(models.Model):", output) + def test_managed_models(self): """ By default the command generates models with `Meta.managed = False`. |