将ImageFields添加到模型

时间:2018-08-13 23:10:59

标签: python django

我想在“模型”的模型名称中添加ImageField, 但是管理面板失败。 我是初学者...我的失败是我知道的非常基本的例外,但我无法解决。

我该怎么办? (对不起,我英语不好,我是高中生)

型号代码

from django.db import models

# Create your models here.

#create a model and some models
class posting (models.Model):
    title=models.CharField(max_length=120,verbose_name='Başlık')
    content=models.TextField(verbose_name="İçerik")
    publishing_date=models.DateTimeField(verbose_name="Yayınlanma tarihi")
    photo=models.ImageField()

    #herposta title ına göre indexliyor

    def __str__(self):
        return self.title

异常说明:

OperationalError at /admin/posting/posting/
no such column: posting_posting.photo
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/posting/posting/
Django Version: 1.10
Exception Type: OperationalError
Exception Value:    
no such column: posting_posting.photo
Exception Location: C:\Users\Lenovo\Desktop\blog\venv\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 337
Python Executable:  C:\Users\Lenovo\Desktop\blog\venv\Scripts\python.exe
Python Version: 3.7.0
Python Path:    
['C:\\Users\\Lenovo\\Desktop\\blog',
 'C:\\Users\\Lenovo\\Desktop\\blog\\venv\\Scripts\\python37.zip',
 'C:\\Users\\Lenovo\\Desktop\\blog\\venv\\DLLs',
 'C:\\Users\\Lenovo\\Desktop\\blog\\venv\\lib',
 'C:\\Users\\Lenovo\\Desktop\\blog\\venv\\Scripts',
 'c:\\users\\lenovo\\appdata\\local\\programs\\python\\python37-32\\Lib',
 'c:\\users\\lenovo\\appdata\\local\\programs\\python\\python37-32\\DLLs',
 'C:\\Users\\Lenovo\\Desktop\\blog\\venv',
 'C:\\Users\\Lenovo\\Desktop\\blog\\venv\\lib\\site-packages']
Server time:    Sal, 14 Ağu 2018 02:01:09 +0300`enter code here`

1 个答案:

答案 0 :(得分:0)

很可能,您仍然需要创建数据库迁移manage.py makemigrations,然后运行它manage.py migrate