mirror of
https://github.com/django/django.git
synced 2025-07-23 05:05:17 +00:00
Fixed #28391 -- Fixed Cast() with CharField and max_length on MySQL.
Thanks Tim Graham for the review.
This commit is contained in:
parent
feeafdad02
commit
776cee9749
5 changed files with 20 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
|||
from django.db import models
|
||||
from django.db.models.expressions import Value
|
||||
from django.db.models.functions import Cast
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, ignore_warnings, skipUnlessDBFeature
|
||||
|
||||
from .models import Author
|
||||
|
||||
|
@ -19,6 +19,13 @@ class CastTests(TestCase):
|
|||
numbers = Author.objects.annotate(cast_string=Cast('age', models.CharField(max_length=255)),)
|
||||
self.assertEqual(numbers.get().cast_string, '1')
|
||||
|
||||
# Silence "Truncated incorrect CHAR(1) value: 'Bob'".
|
||||
@ignore_warnings(module='django.db.backends.mysql.base')
|
||||
@skipUnlessDBFeature('supports_cast_with_precision')
|
||||
def test_cast_to_char_field_with_max_length(self):
|
||||
names = Author.objects.annotate(cast_string=Cast('name', models.CharField(max_length=1)))
|
||||
self.assertEqual(names.get().cast_string, 'B')
|
||||
|
||||
def test_cast_to_integer(self):
|
||||
for field_class in (
|
||||
models.IntegerField,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue