1

这是我的model.py

from django.db import models

class Flower(models.Model):
    name = models.CharField(max_length = 30)
    price = models.IntegerField()
    image = models.ImageField(upload_to = 'static/media')
    def __unicode__(self):
        return self.name

网址.py

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

    urlpatterns = patterns('',
        # Examples:
        url(r'^$', 'site1.views.home', name='home'),
        # url(r'^mysite1/', include('mysite1.foo.urls')),

        # Uncomment the admin/doc line below to enable admin documentation:
        # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

        # Uncomment the next line to enable the admin:
        url(r'^admin/', include(admin.site.urls)),
    )

管理员.py

from django.contrib import admin
from site1.models import Flower

admin.site.register(Flower)

完整回溯

Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in wrapper
  366.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in inner
  196.             return view(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapper
  25.             return bound_func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in bound_func
  21.                 return func(self, *args2, **kwargs2)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in changelist_view
  1233.             'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in __len__
  85.                 self._result_cache = list(self.iterator())
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in iterator
  291.         for row in compiler.results_iter():
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in results_iter
  763.         for rows in self.execute_sql(MULTI):
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  818.         cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/util.py" in execute
  40.             return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py" in execute
  344.             return Database.Cursor.execute(self, query, params)

Exception Type: DatabaseError at /admin/site1/flower/
Exception Value: no such column: site1_flower.image

我想从管理面板将图像上传到我的站点数据库,这样我就可以在任何我想要的地方查看这些图像。但我遇到了一个错误:

DatabaseError at /admin/site1/flower/
no such column: site1_flower.image
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/site1/flower/
Django Version: 1.4.3
Exception Type: DatabaseError
Exception Value:    
no such column: site1_flower.image

我该如何克服这个问题。

4

1 回答 1

0

根据 *Exception Value: no such column: site1_flower.image* 我想,你在 syncdb 之后添加了 image 字段。因此,图像字段在 db 中不存在。最简单的方法是完全删除 Flower 模型并再次运行 syncdb。或者您可以在您的数据库中手动创建此字段。但最好的方法是使用django south

于 2013-07-25T09:49:45.740 回答