Syncdb无法正常工作

时间:2015-03-23 16:15:11

标签: python django django-imagekit syncdb

from django.db import models
from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFill

class Product(models.Model):

class Meta():
    db_table = 'tovar'


product_title = models.CharField(max_length=200)
product_img = models.ImageField(upload_to='images')
avatar = models.ImageField(upload_to='avatars')
avatar_thumbnail = ImageSpecField(source='avatar',processors=[ResizeToFill(100, 50)],format='JPEG',options={'quality': 60})
product_categories = models.ForeignKey(Category)
product_subcategories = models.ForeignKey(Subcategory)
product_description = models.TextField()


def __unicode__(self):
    return self.product_title


profile = Product.objects.all()[0]
print(profile.avatar_thumbnail.url)    
print(profile.avatar_thumbnail.width)  

不要使用manage.py syncdb

错误:

django.db.utils.OperationalError:没有这样的表:tovar

请帮助我

3 个答案:

答案 0 :(得分:1)

'python manage.py syncdb'不适用于Django 1.9或更高版本,请尝试此代码!

  • python manage.py makemigrations

  • python manage.py migrate

  • python manage.py migrate --run-syncdb

我和Django 1.9和1.10有同样的问题。这段代码有效!

答案 1 :(得分:0)

如果您修改了模型,首先必须运行

manage.py schemamigration your_django_application_name --auto

然后你跑:

manage.py migrate your_django_application_name

答案 2 :(得分:0)

使用以下命令

>>python manage.py sqlmigrate  application_name 0001

如果你有更多的表,那么将数字增加到ooo2并再次运行abe代码

>>python manage.py runserver