2011-08-02 67 views
1

我創建了以下我無法訪問連接通過管理站點添加任何連接對象模型數據庫錯誤:沒有這樣的列:connect_connect.reciever_id

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 
+1

reciever!=接收器。你的拼寫是否一致? –

+0

雅我使用了與「接收者」相同的拼寫。雖然我現在要改變它。 –

回答

5

你的receiver字段添加到模型最初創建connect_connect表後?如果是這樣,您必須手動將該字段添加到數據庫中(Django不會自動將更改與數據庫同步到模型中。)

只需啓動交互式db shell,通常爲dbshell,然後添加該字段。在MySQL中它會是這樣的:

ALTER TABLE connect_connect ADD COLUMN receiver_id integer; 

我建議你運行manage.py sqlall appname看看Django是如何將現在創建數據庫表,然後確保數據庫匹配通過你的數據庫外殼進行必要的改變。

+0

我沒有任何reciever_id字段在我的模型中。這是什麼感到驚訝! –

+3

它是你的'receiver'字段。由於它代表的是ForeignField,所以Django在db中將它創建爲'receiver_id'。如果你不關心你已有的數據,你可以運行'manage.py reset appname'來同步你的模型和數據庫,否則我會建議運行'manage.py sqlall appname'來看看Django如何創建你的數據庫表,然後確保數據庫匹配,通過你的數據庫外殼進行必要的更改。 –

+0

它顯示reciever_id作爲字段時,我做sqlall爲:「reciever_id」整數非空參考「connect_connecttofrom」(「id」) –