1

Please dont mark it as dupliacte .I have been searching for three days on community I am using alibaba cloud services for hosting and I got this error django.db.utils.operationalerror: (1071, 'specified key was too long; max key length is 767 bytes') when i run python3 manage.py migrate my problem is similar as mentioned here Django deploying on MySQL gives #1071 error "Specified key was too long" my model.py file is `

from django.db import models

class SendRequest(models.Model):
    rid=models.AutoField(primary_key=True)
    uname=models.CharField(max_length=256)
    problemcode=models.CharField(max_length=256)
    languageused=models.CharField(max_length=50)
    question=models.TextField()
    description=models.TextField()
    codesnapshot=models.TextField()
    status=models.BooleanField(default=False)
    date = models.DateTimeField(default=datetime.now,null=False)

class ReceiveRequest(models.Model):
    rrid=models.ForeignKey(SendRequest,on_delete=models.CASCADE)
    uname=models.CharField(max_length=256)
    class Meta:`enter code here`
        unique_together = (("rrid", "uname"),)`

When i use SendRequest Model i didnt get any error but when i add ReceiveRequest table i got the above error **my settings.py is **

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME'  : 'dbdiv',
        'USER'  :  '********',
        'PASSWORD':'********',
        'HOST'  :  'rm-6gjg9lt559w00uv6yeo.mysql.ap-south-1.rds.aliyuncs.com',
        'PORT'  :  '3306',
        'OPTIONS': {
            'init_command':'SET character_set_connection=utf8,collation_connection=utf8_unicode_ci',
        },

    }
}

I tried all possible ways by dropping and adding database again and i created database with CREATE DATABASE dbdiv CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; Please help me . my problem is similar to Django deploying on MySQL gives #1071 error "Specified key was too long" mention answer

  • Looks like a duplicate to me [Specified key was too long](https://stackoverflow.com/questions/1814532/1071-specified-key-was-too-long-max-key-length-is-767-bytes). Do you really expect your uname and problem code to be 256 characters long in utf8[mb3/4}? Change them to the actual expected maximum length (<=191 will avoid this problem however make them the length expected). – danblack Sep 15 '18 at 03:34
  • 1
    Please add the full error traceback to your question! – Klaus D. Sep 15 '18 at 03:35
  • Yeah i tried by putting char length to 50 in all char fields but it doesn't help me In between if i use only Sendrequest table only there is no problem. if i add requesttable alone problem is rising to me. – VSaiNagendra Sep 15 '18 at 03:39
  • Did you configure your db to be MYISAM or INNODB? – dirkgroten Sep 15 '18 at 12:20
  • Look at [this thread](https://stackoverflow.com/questions/29782081/django-db-utils-operationalerror-1071-specified-key-was-too-long-max-key-le#43365860) as well, it might give you some answers. – dirkgroten Sep 15 '18 at 12:20

0 Answers0