I am very new to Python and working on the djbyexample tutorial. I continue to get an operationalerror related to one of my two models and im not sure why (though i'm sure its an obvious answer).
I've set up two models:
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
And my admin.py is as follows:
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)
When attempting to access the Items model through the live admin I get the following Traceback:
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
Your database does not match your model. Either remove the table and resync, or use a migration tool to modify the table to match your model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With