django中的syncdb问题

时间:2014-05-12 13:37:10

标签: python mysql django

我的django应用程序如何继续出现此错误?我在webfaction上使用mysql,这是标准的,我已将其设置为UTF8 - 我真的不能理解这个

“无法为feed.Genre模型安装索引:指定密钥太长;最大密钥长度为767字节”

这是我的模特

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

1 个答案:

答案 0 :(得分:1)

我认为这是MySQL中VARCHAR字段长度的问题。

您正在使用SlugField,后台也使用VARCHAR,与CharField的方式相同。相同的长度限制适用于这两个字段,因此在段塞字段中设置max_length=300是一个问题(300 * 3字节是900字节,超过最大值767,如错误所示。如果您想知道在767来自的地方,255 chars * 3 bytes per char是765字节+ 2 bytes prefix)。

max_length字段的SlugField属性降低到255,您就可以了。