mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #30757 -- Added a system check to ensure max_length fits the longest choice.
This commit is contained in:
parent
fee75d2aed
commit
b6251956b6
3 changed files with 45 additions and 0 deletions
|
@ -304,6 +304,32 @@ class CharFieldTests(SimpleTestCase):
|
|||
|
||||
self.assertEqual(Model._meta.get_field('field').check(), [])
|
||||
|
||||
def test_choices_in_max_length(self):
|
||||
class Model(models.Model):
|
||||
field = models.CharField(
|
||||
max_length=2, choices=[
|
||||
('ABC', 'Value Too Long!'), ('OK', 'Good')
|
||||
],
|
||||
)
|
||||
group = models.CharField(
|
||||
max_length=2, choices=[
|
||||
('Nested', [('OK', 'Good'), ('Longer', 'Longer')]),
|
||||
('Grouped', [('Bad', 'Bad')]),
|
||||
],
|
||||
)
|
||||
|
||||
for name, choice_max_length in (('field', 3), ('group', 6)):
|
||||
with self.subTest(name):
|
||||
field = Model._meta.get_field(name)
|
||||
self.assertEqual(field.check(), [
|
||||
Error(
|
||||
"'max_length' is too small to fit the longest value "
|
||||
"in 'choices' (%d characters)." % choice_max_length,
|
||||
obj=field,
|
||||
id='fields.E009',
|
||||
),
|
||||
])
|
||||
|
||||
def test_bad_db_index_value(self):
|
||||
class Model(models.Model):
|
||||
field = models.CharField(max_length=10, db_index='bad')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue