Home > Software design >  django.db.utils.OperationalError: (1074, "Column length too big for column 'value' (m
django.db.utils.OperationalError: (1074, "Column length too big for column 'value' (m

Time:01-20

I am trying to host my website using FileZilla and PuTTY. For that, I have added the code in FileZilla remote site and I have created a database named jobs using following commands in PuTTY app.

sudo mysql -u root #For Maria DB
CREATE DATABASE jobs;
GRANT ALL PRIVILEGES ON jobs.*TO 'hello'@'localhost';
flush privileges;
exit

Then python3 manage.py makemigrations command is executed and after that when I executed the python3 manage.py migrate command I got an error like this.

django.db.utils.OperationalError: (1074, "Column length too big for column 'value' (max = 16383); use BLOB or TEXT instead")

models.py

class IndividualProfile(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    Address_line_1 = models.CharField(max_length=300)
    Address_line_2 = models.CharField(max_length=300)
    city = models.CharField(max_length=100)
    state = models.CharField(max_length=100)
    Country = models.CharField(max_length=100)
    postal_code =models.CharField(max_length=100)
    gender = models.CharField(max_length=11, choices=GENDER_SELECT)
    alternate_number = PhoneNumberField(unique=True, blank=False, null=False)
    aadhar_number = models.CharField(max_length=50)
    designation = models.CharField(max_length=50)
    skills = models.CharField(max_length=5000)
    resume = models.FileField(upload_to='resume', blank=True, null=True, validators=[FileExtensionValidator(['pdf'])])
    profile_pic = models.ImageField(upload_to='individual_profile_pic', validators=[FileExtensionValidator(['jpg','png','jpeg'])])
    academic_qualification = models.CharField(max_length=500)

Can anyone suggest a solution to solve this issue?

CodePudding user response:

There are limitations in saving large data in Charfiled.

You can make use of TextField to solve this issue

So change

skills = models.CharField(max_length=5000)

to

skills = models.TextField(max_length=5000)

If you specify a max_length attribute, it will be reflected in the Textarea widget of the auto-generated form field. However it is not enforced at the model or database level. Use a CharField for that. :- Doc

  •  Tags:  
  • Related