Skip to content

Loading…

Fixed #20974 -- Added test for Mysql specific validation. #2394

Closed
wants to merge 1 commit into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 25 additions and 0 deletions.
  1. +25 −0 tests/backends/tests.py
View
25 tests/backends/tests.py
@@ -153,6 +153,31 @@ def test_autoincrement(self):
else:
self.assertFalse(found_reset)
+ @unittest.skipUnless(connection.vendor == 'mysql',
+ "Test valid only for MySQL")
+ def test_mysql_specific_validation(self):
+ from django.db import models
+ from django.core.checks import Error
+ """
+ Test that no character (varchar) fields can have a length
+ exceeding 255 characters if they have a unique index on them.
+ """
+ class ModelForMysqlValidation(models.Model):
+ field1 = models.CharField(unique=True, max_length=256)
+
+ field = ModelForMysqlValidation._meta.get_field('field1')
+ errors = ModelForMysqlValidation.check()
+ expected = [
+ Error(
+ 'MySQL does not allow unique CharFields to have a max_length > 255.',
+ hint=None,
+ obj=field,
+ id='mysql.E001',
+ )
+ ]
+
+ self.assertEqual(errors, expected)
+
class DateQuotingTest(TestCase):
Something went wrong with that request. Please try again.