gpt4 book ai didi

python - 操作错误 : No such Column

转载 作者:太空狗 更新时间:2023-10-30 01:01:54 26 4
gpt4 key购买 nike

我是 Python 的新手,正在研究 djbyexample 教程。我继续收到与我的两个模型之一相关的操作错误,我不确定为什么(尽管我确定这是一个明显的答案)。

我设置了两个模型:

from django.db import models

class DateTime(models.Model):
datetime = models.DateTimeField(auto_now_add=True)

def __unicode__(self):
return unicode(self.datetime)

class Item(models.Model):
name = models.CharField(max_length=60)
created= models.ForeignKey(DateTime)
priority = models.IntegerField(default=0)
difficulty = models.IntegerField(default=0)
done = models.BooleanField(default=False)

def __str__(self):
return self.name

而我的admin.py如下:

from django.contrib import admin

from models import Item, DateTime

class ItemAdmin(admin.ModelAdmin):
list_display = ["name","priority","difficulty","created","done"]
search_fields = ["name"]

class ItemInline(admin.TabularInline):
model = Item

class DateAdmin(admin.ModelAdmin):
list_display = ["datetime"]
inlines = [ItemInline]

admin.site.register(Item,ItemAdmin)
admin.site.register(DateTime,DateAdmin)

当尝试通过在线管理员访问 Items 模型时,我得到以下回溯:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/admin/todo/item/

Django Version: 1.6.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'todo',
'south')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
432. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
52. response = view_func(request, *args, **kwargs)
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
198. return view(request, *args, **kwargs)
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
29. return bound_func(*args, **kwargs)
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
25. return func(self, *args2, **kwargs2)
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in changelist_view
1411. 'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/db/models/query.py" in __len__
77. self._fetch_all()
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all
854. self._result_cache = list(self.iterator())
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/db/models/query.py" in iterator
220. for row in compiler.results_iter():
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter
710. for rows in self.execute_sql(MULTI):
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
781. cursor.execute(sql, params)
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/db/backends/util.py" in execute
69. return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/db/backends/util.py" in execute
53. return self.cursor.execute(sql, params)
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/db/utils.py" in __exit__
99. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/db/backends/util.py" in execute
53. return self.cursor.execute(sql, params)
File "/home/blake/.virtualenvs/Todo_List/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py" in execute
450. return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /admin/todo/item/
Exception Value: no such column: todo_item.created_id

最佳答案

您的数据库与您的模型不匹配。删除表并重新同步,或使用迁移工具修改表以匹配您的模型。

关于python - 操作错误 : No such Column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21457563/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com