error in accessing table created in django in the python code

China☆狼群 提交于 2019-12-11 08:14:56

问题


Now on writing path as sys.path.insert(0,'/home/pooja/Desktop/mysite'), it ran fine asked me for the word tobe searched and gave this error:

Traceback (most recent call last):

File "call.py", line 32, in

s.save()

File "/usr/local/lib/python2.6/dist-packages/django/db/models/base.py", line 463, in save

self.save_base(using=using, force_insert=force_insert, force_update=force_update)

File "/usr/local/lib/python2.6/dist-packages/django/db/models/base.py", line 524, in

save_base

manager.using(using).filter(pk=pk_val).exists())):

File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 562, in exists

return self.query.has_results(using=self.db)

File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.py", line 441, in has_results

return bool(compiler.execute_sql(SINGLE))

File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 818, in execute_sql

cursor.execute(sql, params)

File "/usr/local/lib/python2.6/dist-packages/django/db/backends/util.py", line 40, in execute

return self.cursor.execute(sql, params) File "/usr/local/lib/python2.6/dist-packages/django/db/backends/sqlite3/base.py", line 337, in execute return Database.Cursor.execute(self, query, params)

django.db.utils.DatabaseError: no such table: search_keywords

Please help!!


回答1:


The exception says: no such table: search_keywords, which is quite self-explanatory and means that there is no database table with such name. So:

  1. You may be using relative path to db file in settings.py, which resolves to a different db depending on place where you execute the script. Try to use absolute path and see if it helps.

  2. You have not synced your models with the database. Run manage.py syncdb to generate the database tables.



来源:https://stackoverflow.com/questions/11307928/error-in-accessing-table-created-in-django-in-the-python-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!