我正在Django中创建一个Web应用程序,用户可以在他/她的帐户中存储文件。
当我想将ProgrammingError
用作User
时,我得到ForeignKey
。
以下是models.py
from django.db import models
from django.contrib.auth.models import User
class InputFiles(models.Model):
input_user = models.ForeignKey(User)
audio_file = models.FileField(upload_to='\media')
text_file = models.CharField(max_length=200)
可以通过管理页面查看此表。当我评论input_user
(我使用South来更新表格)时,我可以通过管理页面查看此表格。
但是,当我评论input_user
时,我收到以下错误:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/nalign_app_recorder/inputfiles/
Django Version: 1.6.1
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'gunicorn',
'nalign_app_recorder',
'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 "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
112. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/options.py" in wrapper
432. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
52. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in inner
198. return view(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapper
29. return bound_func(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py" in bound_func
25. return func(self, *args2, **kwargs2)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/options.py" in changelist_view
1411. 'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},
File "/usr/lib/python2.7/dist-packages/django/db/models/query.py" in __len__
77. self._fetch_all()
File "/usr/lib/python2.7/dist-packages/django/db/models/query.py" in _fetch_all
854. self._result_cache = list(self.iterator())
File "/usr/lib/python2.7/dist-packages/django/db/models/query.py" in iterator
220. for row in compiler.results_iter():
File "/usr/lib/python2.7/dist-packages/django/db/models/sql/compiler.py" in results_iter
710. for rows in self.execute_sql(MULTI):
File "/usr/lib/python2.7/dist-packages/django/db/models/sql/compiler.py" in execute_sql
781. cursor.execute(sql, params)
File "/usr/lib/python2.7/dist-packages/django/db/backends/util.py" in execute
69. return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/lib/python2.7/dist-packages/django/db/backends/util.py" in execute
53. return self.cursor.execute(sql, params)
File "/usr/lib/python2.7/dist-packages/django/db/utils.py" in __exit__
99. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/lib/python2.7/dist-packages/django/db/backends/util.py" in execute
53. return self.cursor.execute(sql, params)
Exception Type: ProgrammingError at /admin/nalign_app_recorder/inputfiles/
Exception Value: column nalign_app_recorder_inputfiles.input_user_id does not exist
LINE 1: SELECT "nalign_app_recorder_inputfiles"."id", "nalign_app_re...
有没有人知道解决方法。
答案 0 :(得分:2)
我终于找到了答案。
我猜问题出现了,因为south
无法添加新条目。因此,我清理了数据库并重新开始。
当我做以下事情时,问题就消失了:
命令如下:
sudo rm -r myapp/migrations/
sudo python manage.py sqlflush | python manage.py dbshell
sudo python manage.py syncdb
sudo python manage.py convert_to_south myapp
sudo python manage.py createsuperuser
答案 1 :(得分:0)
InputFiles表没有input_user列。尝试执行' manage.py syncdb'更新数据库..