'#13711 -- Model check for long M2M column names when database has
column name length limits.'

@unittest.skipIf((max_column_name_length is None), "The    database    doesn't    have    a    column    name    length    limit.")
def test_M2M_long_column_name(self):

    (allowed_len, db_alias) = get_max_column_name_length()
    class VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz(models.Model, ):
        title = models.CharField(max_length=11)
    class ModelWithLongField(models.Model, ):
        m2m_field = models.ManyToManyField(VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, related_name='rn1')
        m2m_field2 = models.ManyToManyField(VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, related_name='rn2', through='m2msimple')
        m2m_field3 = models.ManyToManyField(VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, related_name='rn3', through='m2mcomplex')
        fk = models.ForeignKey(VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, models.CASCADE, related_name='rn4')
    class m2msimple(models.Model, ):
        id2 = models.ForeignKey(ModelWithLongField, models.CASCADE)
    class m2mcomplex(models.Model, ):
        id2 = models.ForeignKey(ModelWithLongField, models.CASCADE)
    long_field_name = ('a' * (self.max_column_name_length + 1))
    models.ForeignKey(VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, models.CASCADE).contribute_to_class(m2msimple, long_field_name)
    models.ForeignKey(VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, models.CASCADE, db_column=long_field_name).contribute_to_class(m2mcomplex, long_field_name)
    errors = ModelWithLongField.check()
    m2m_long_name = 'verylongmodelnamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz_id'
    if (self.max_column_name_length > len(m2m_long_name)):
        expected = []
    else:
        expected = [Error(('Autogenerated    column    name    too    long    for    M2M    field    "%s".    Maximum    length    is    "%s"    for    database    "%s".' % (m2m_long_name, self.max_column_name_length, self.column_limit_db_alias)), hint="Use    'through'    to    create    a    separate    model    for    M2M    and    then    set    column_name    using    'db_column'.", obj=ModelWithLongField, id='models.E019')]
    expected.append(Error(('Autogenerated    column    name    too    long    for    M2M    field    "%s_id".    Maximum    length    is    "%s"    for    database    "%s".' % (long_field_name, self.max_column_name_length, self.column_limit_db_alias)), hint="Use    'through'    to    create    a    separate    model    for    M2M    and    then    set    column_name    using    'db_column'.", obj=ModelWithLongField, id='models.E019'))
    self.assertEqual(errors, expected)
