mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
Fixed #30613 -- Moved index name validation to system checks.
This commit is contained in:
parent
f197c3dd91
commit
53209f7830
5 changed files with 64 additions and 35 deletions
|
@ -296,6 +296,39 @@ class IndexesTests(SimpleTestCase):
|
|||
|
||||
self.assertEqual(Bar.check(), [])
|
||||
|
||||
def test_name_constraints(self):
|
||||
class Model(models.Model):
|
||||
class Meta:
|
||||
indexes = [
|
||||
models.Index(fields=['id'], name='_index_name'),
|
||||
models.Index(fields=['id'], name='5index_name'),
|
||||
]
|
||||
|
||||
self.assertEqual(Model.check(), [
|
||||
Error(
|
||||
"The index name '%sindex_name' cannot start with an "
|
||||
"underscore or a number." % prefix,
|
||||
obj=Model,
|
||||
id='models.E033',
|
||||
) for prefix in ('_', '5')
|
||||
])
|
||||
|
||||
def test_max_name_length(self):
|
||||
index_name = 'x' * 31
|
||||
|
||||
class Model(models.Model):
|
||||
class Meta:
|
||||
indexes = [models.Index(fields=['id'], name=index_name)]
|
||||
|
||||
self.assertEqual(Model.check(), [
|
||||
Error(
|
||||
"The index name '%s' cannot be longer than 30 characters."
|
||||
% index_name,
|
||||
obj=Model,
|
||||
id='models.E034',
|
||||
),
|
||||
])
|
||||
|
||||
|
||||
@isolate_apps('invalid_models_tests')
|
||||
class FieldNamesTests(SimpleTestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue