django.db.utils.OperationalError: (1071, 'Specified key was too long; max key length is 767 bytes')

前端 未结 7 636
故里飘歌
故里飘歌 2020-12-15 09:03

My model:

class Course(models.Model):
    language = models.ForeignKey(Language)
    name = models.CharField(max_length=50, unique=True, default=\'course\')
         


        
相关标签:
7条回答
  • 2020-12-15 09:52

    I think all 4 of these things are needed:

    SET GLOBAL innodb_file_per_table = ON,
               innodb_file_format = Barracuda,
               innodb_large_prefix = ON;
    CREATE/ALTER TABLE ...
        ROW_FORMAT = DYNAMIC or COMPRESSED
    

    This should get past the limit of 767 bytes for one column, but won't get past the 3072 bytes limit for the entire index.

    In order to have a compound unique index composed of strings, normalize some of the strings. Replacing a long string with a 4-byte INT will shrink the index below the limit.

    0 讨论(0)
提交回复
热议问题