Categories: Article

How to solve #1170-blob/text column variable key specification


#1170 – Blob/Text Column ‘Variable’ Used In Key Specification Without A Key Length In Django

If you having 1170 – Blob/Text Column ‘Variable’ Used In Key Specification error and you have search for solution you didn’t see, then welcome at the end of this article you will be able to solve your problem.

How to solve #1170 – BLOB/TEXT column ‘variable’ used in key specification without a key length in django

The error message you have  encountered  (#1170) usually comes up  in MySQL when you’re trying to create an index on a column of data type BLOB or TEXT without specifying a key length.

Or some times you might been on sqLite then you might want to migrate to MySql then the error will pop up if you have set a unique constraint without specifying a key length.

Say for example you have added unique key in slug then you must specify a key length in the title, also you must also specify a key length in the slug it self .

lets say you have a model then with title and slug then you want a unique constrant in such a way that all your slug would be unique then to solve thisÂ

Steps required in solving #1170 – BLOB/TEXT column ‘variable’ used in key specification without a key length in django

from django.db import models
from django.utils.text import slugify

class Blog(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField(unique=True, blank=True)

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.title)
        super().save(*args, **kwargs)

    def __str__(self):
        return self.title

Since you have specify a key length in the title the error will disappearÂ

To resolve this issue, you need to ensure that you provide a key length when creating an index on columns of these data types.

You don’t need to enter into  your db to resolve this issue, just make sure that you specify a key length in some of the fields you have like title, Slug, category etcÂ

Here’s an example of how you can modify your index creation statement

how to install burp suite in Kali Linux

benny

I am graduate of Mathematics and Mechatronics Engineering. I am a lover of Python. I love writing about tech.

Recent Posts

What are the common characteristics of philosophy and science?

Within the broad field of human research, philosophical and scientific inquiry has had a particularly…

2 weeks ago

What is the relationship between philosophy and science

In our world, there are two major approaches to understanding things: philosophy and science. They…

2 weeks ago

How to Make Your Mac Faster: Clearing Cache in Simple Steps

Is your Mac feeling sluggish? One easy fix might be to clear its cache. Cache…

3 weeks ago

How to Show Hidden Files on a Mac

How to show Hidden files on Your Mac? Have you ever wondered what's hiding on…

3 weeks ago

How to Uninstall Apps on MacBook ?

Uninstall apps on MacBook is another thing a Mac user should be worried of in…

3 weeks ago

How hackers uses Nethunter Kali linux to hack Facebook

Disclaimer; This tutorial is for self awareness for you to know how hackers hack your…

3 weeks ago

This website uses cookies to enhance your browsing experience, personalize content and ads, provide social media features, and analyze traffic. By clicking "Accept", you consent to the use of cookies and similar technologies as outlined in our Cookie Policy and Privacy Policy. We will NEVER sell your data Note: By accepting, you agree to our Cookie Policy, Privacy Policy, and Ads Consent. You can manage your preferences or opt-out in your browser settings.

Read More