Django说:表X没有名为Y的列。我不同意

时间:2010-07-16 22:16:54

标签: database django django-models

我收到以下错误:

sqlite3.OperationalError: table gallery_image has no column named filename

这是我的模特:

from django.db import models

class Image(models.Model):
    filename= models.Field(max_length=40);
    gallery = models.ForeignKey('Gallery')
    def __unicode__(self):
        return u'%s(%s)' % (self.filename,self.gallery)

class Gallery(models.Model):
    title   = models.CharField(max_length=100)
    url     = models.CharField(max_length=50, unique=True)
    def __unicode__(self):
        return u'title: %s, url: %s' % (self.title, self.url)

这个脚本显然在最后一行有错误

from django.core.management.base import BaseCommand
from dev.gallery.models import Gallery, Image
import os

class Command(BaseCommand):
    def handle(self, *args, **options):
        importfrom='/srv/django/dev/gallery/import'
        exportto='/var/www/dev-media/'

        title=args[0]
        url=args[1]

        print(os.listdir(importfrom))

        if not len(args)==2:
            print 'wrong number of arguments'
            return ;

        #Create the gallery in the database
        g=Gallery(title=title,url=title)
        g.save();

        files=os.listdir('/srv/django/dev/gallery/import');

        for f in files:
            Image(filename=f,gallery=g).save();

如果这对您有意义,请向我解释原因:)

1 个答案:

答案 0 :(得分:1)

filename应该是FileField的实例,而不仅仅是Field