当前位置:  开发笔记 > 编程语言 > 正文

数据库错误:没有这样的列:connect_connect.reciever_id

如何解决《数据库错误:没有这样的列:connect_connect.reciever_id》经验,为你挑选了1个好方法。

我创建了以下模型

 class ConnectToFrom(models.Model):
    person = models.ForeignKey(User, null=True)
    kiosk = models.ForeignKey(Kiosks, null=True)

 class Connect(models.Model):
    parent_id = models.ForeignKey("self", null = True, blank = True)
    sender = models.ForeignKey(ConnectToFrom, related_name='sent_messages' )
    reciever = models.ForeignKey(ConnectToFrom, related_name='received_messages')
    .
    .
    .

我无法通过管理站点访问连接以添加任何连接对象!我不能将相同的模型引用到两个字段吗?我无法弄清楚导致错误的确切原因.请帮忙

追溯 :

Environment:


Request Method: GET
Request URL: http://www.krisvenham.com:8000/admin/connect/connect/

Django Version: 1.3
Python Version: 2.6.6
Installed Applications:
['broadcast',
 'shastra',
 'fb_api',
 'log',
 'nties',
 'crc',
 'connect',
 'network',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.admin',
 'kiosks',
 'content',
 'home',
 'dashboard',
 'trial',
 'meta',
 'oembed']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "C:\Python26\lib\site-packages\django\contrib\admin\options.py" in wrapper
  307.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Python26\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  79.         response = view_func(request, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\contrib\admin\sites.py" in inner
  197.             return view(request, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\utils\decorators.py" in _wrapper
  28.             return bound_func(*args, **kwargs)
File "C:\Python26\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\utils\decorators.py" in bound_func
  24.                 return func(self, *args2, **kwargs2)
File "C:\Python26\lib\site-packages\django\contrib\admin\options.py" in changelist_view
  1159.             'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},
File "C:\Python26\lib\site-packages\django\db\models\query.py" in __len__
  82.                 self._result_cache = list(self.iterator())
File "C:\Python26\lib\site-packages\django\db\models\query.py" in iterator
  273.         for row in compiler.results_iter():
File "C:\Python26\lib\site-packages\django\db\models\sql\compiler.py" in results_iter
  680.         for rows in self.execute_sql(MULTI):
File "C:\Python26\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
  735.         cursor.execute(sql, params)
File "C:\Python26\lib\site-packages\django\db\backends\util.py" in execute
  34.             return self.cursor.execute(sql, params)
File "C:\Python26\lib\site-packages\django\db\backends\sqlite3\base.py" in execute
  234.             return Database.Cursor.execute(self, query, params)

Exception Type: DatabaseError at /admin/connect/connect/
Exception Value: no such column: connect_connect.reciever_id

rolling ston.. 5

receiver最初创建connect_connect表后,是否将字段添加到模型中?如果是这样,您将不得不手动将该字段添加到您的数据库(Django不会自动将您的模型的更改与数据库同步.)

通常dbshell,只需启动交互式数据库shell ,然后添加该字段.在MySQL中它将是这样的:

ALTER TABLE connect_connect ADD COLUMN receiver_id integer;

我建议运行manage.py sqlall appname以查看Django现在如何创建db表,然后通过db shell进行必要的更改来确保db匹配它.



1> rolling ston..:

receiver最初创建connect_connect表后,是否将字段添加到模型中?如果是这样,您将不得不手动将该字段添加到您的数据库(Django不会自动将您的模型的更改与数据库同步.)

通常dbshell,只需启动交互式数据库shell ,然后添加该字段.在MySQL中它将是这样的:

ALTER TABLE connect_connect ADD COLUMN receiver_id integer;

我建议运行manage.py sqlall appname以查看Django现在如何创建db表,然后通过db shell进行必要的更改来确保db匹配它.


它是你的`接收者'领域.因为它代表一个ForeignField Django在db中创建它作为`receiver_id`.如果您不关心已有的数据,可以运行`manage.py reset appname`来同步模型和数据库,否则我建议运行`manage.py sqlall appname`来看看Django如何创建你的现在使用db表,然后通过db shell进行必要的更改,确保db匹配该表.
推荐阅读
coco2冰冰
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有