Fixed #33643 -- Fixed inspectdb crash on functional unique constraints on Oracle.
This commit is contained in:
parent
a1e4e86f92
commit
e12670016b
|
@ -350,7 +350,9 @@ class Command(BaseCommand):
|
||||||
columns = params["columns"]
|
columns = params["columns"]
|
||||||
if None in columns:
|
if None in columns:
|
||||||
has_unsupported_constraint = True
|
has_unsupported_constraint = True
|
||||||
columns = [x for x in columns if x is not None]
|
columns = [
|
||||||
|
x for x in columns if x is not None and x in column_to_field_name
|
||||||
|
]
|
||||||
if len(columns) > 1:
|
if len(columns) > 1:
|
||||||
unique_together.append(
|
unique_together.append(
|
||||||
str(tuple(column_to_field_name[c] for c in columns))
|
str(tuple(column_to_field_name[c] for c in columns))
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from django.db import connection, models
|
from django.db import connection, models
|
||||||
|
from django.db.models.functions import Lower
|
||||||
|
|
||||||
|
|
||||||
class People(models.Model):
|
class People(models.Model):
|
||||||
|
@ -117,3 +118,16 @@ class UniqueTogether(models.Model):
|
||||||
("from_field", "field1"),
|
("from_field", "field1"),
|
||||||
("non_unique", "non_unique_0"),
|
("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"}
|
||||||
|
|
|
@ -330,6 +330,13 @@ class InspectDBTestCase(TestCase):
|
||||||
output = out.getvalue()
|
output = out.getvalue()
|
||||||
self.assertIn("class InspectdbSpecialTableName(models.Model):", output)
|
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):
|
def test_managed_models(self):
|
||||||
"""
|
"""
|
||||||
By default the command generates models with `Meta.managed = False`.
|
By default the command generates models with `Meta.managed = False`.
|
||||||
|
|
Loading…
Reference in New Issue