user3482036
user3482036

Reputation: 109

Issue with syncdb in django

What do I keep getting this error on my django app? I am using mysql on webfaction which is standard and I have set this to UTF8 - I really cant put my head around this

"Failed to install index for feeds.Genre model: Specified key was too long; max key length is 767 bytes"

this is my model

from django.db import models
import uuid
import os


class Messages(models.Model):
    name = models.CharField(max_length=255)
    message = models.CharField(max_length=255)
    show = models.DateTimeField(auto_now_add=True)
    hide = models.DateTimeField()
    def __unicode__(self):
        return self.name 





class Genre(models.Model):
    name = models.CharField(max_length=255)
    slug = models.SlugField(max_length=300)
    meta = models.TextField(max_length=300)
    description = models.TextField(max_length=300)
    created = models.DateTimeField(auto_now_add=True)
    listing = models.BooleanField(default=True)
    def __unicode__(self):
        return self.name


class Category(models.Model):
    name = models.CharField(max_length=255)
    slug = models.SlugField(max_length=300)
    meta = models.TextField(max_length=300)
    description = models.TextField(max_length=300)
    created = models.DateTimeField(auto_now_add=True)
    listing = models.BooleanField(default=True)
    def __unicode__(self):
        return self.name



class Images(models.Model):
    name = models.CharField(max_length=50)
    def get_file_path(instance, filename):
        ext = filename.split('.')[-1]
        filename = "%s.%s" % (uuid.uuid4(), ext)
        return os.path.join( 'images' , filename)
    image = models.ImageField(upload_to = get_file_path, null=True, blank=True)
    def __unicode__(self):
        return self.name  




class Gallery(models.Model):
    name = models.CharField(max_length=50)
    slug = models.SlugField(max_length=300)
    meta = models.TextField(max_length=300)
    description = models.TextField(max_length=300)
    images = models.ManyToManyField(Images)
    def __unicode__(self):
        return self.name    


class Article(models.Model):
    name = models.CharField(max_length=50)
    slug = models.SlugField(max_length=300)
    category = models.ManyToManyField(Category)
    link = models.URLField(max_length=255)
    meta = models.URLField(max_length=255)
    description = models.TextField(max_length=300)
    content = tinymce_models.HTMLField()
    source_name = models.CharField(max_length=50)
    source_link=models.URLField()
    created = models.DateTimeField(auto_now_add=True)
    listing = models.BooleanField(default=True)
    def get_file_path(instance, filename):
        ext = filename.split('.')[-1]
        filename = "%s.%s" % (uuid.uuid4(), ext)
        return os.path.join( 'images' , filename)
    image = models.ImageField(upload_to = get_file_path, null=True, blank=True)
    def __unicode__(self):
        return self.name

Upvotes: 1

Views: 164

Answers (1)

Geekfish
Geekfish

Reputation: 2314

I believe that this is an issue with the length of VARCHAR fields in MySQL.

You are using a SlugField, in the background this is also using VARCHAR the same way that CharField is. The same length limits apply for both fields, so setting max_length=300 in your slug fields is a problem (300 * 3 bytes is 900 bytes, which is over the max of 767, as the error suggests. If you're wondering where 767 comes from, 255 chars * 3 bytes per char is 765 bytes + 2 bytes prefix).

Reduce the max_length attribute of your SlugField fields to 255 and you're good to go.

Upvotes: 1

Related Questions