クエリセットが空で no such column エラー

1,258 views
Skip to first unread message

Hajime Fujita

unread,
Aug 16, 2010, 5:39:13 AM8/16/10
to django-ja
藤田です。
お世話になります。

最近、Python と Django の魅力に取り付かれて、まずは練習のために
RSS リーダーをぼつぼつと作っている初心者です。

該当するデータがデータベースに存在しないときは別処理を行いたいのですが、
例えば、

>>> entries = Entry.objects.all()

とやってから(Entry はデータベースに存在しない)、中身を評価しようとすると、

>>> entries
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line
68, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line
83, in __len__
self._result_cache.extend(list(self._iter))
File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line
238, in iterator
for row in self.query.results_iter():
File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py",
line 287, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py",
line 2369, in execute_sql
cursor.execute(sql, params)
File "/usr/lib/pymodules/python2.6/django/db/backends/util.py", line
19, in execute
return self.cursor.execute(sql, params)
File "/usr/lib/pymodules/python2.6/django/db/backends/sqlite3/
base.py", line 193, in execute
return Database.Cursor.execute(self, query, params)
OperationalError: no such column: rss_main_entry.site_name

というエラーが返ってくるばかりで、if 分岐のための評価すらできません。
この不具合を回避するためにはどうすれば良いのでしょうか?

どうぞよろしくお願い致します。

Yoichi Fujimoto

unread,
Aug 16, 2010, 5:52:50 AM8/16/10
to djan...@googlegroups.com
syncdb した後にモデル弄って、テーブルのカラムが無いとかそんな感じっぽいので、
drop table してから syncdb やり直すとどうでしょう。


2010/8/16 Hajime Fujita <hajime...@gmail.com>:

> --
> -----------------                       http://djangoproject.jp/                         -----------------
> You received this message because you are subscribed to the Google Groups "django-ja" group.
> To post to this group, send email to djan...@googlegroups.com
> To unsubscribe from this group, send email to django-ja-...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/django-ja

Hajime Fujita

unread,
Aug 16, 2010, 6:18:00 AM8/16/10
to django-ja
藤田です。

ご返信ありがとうございます。

すみません、drop table の意味がよく分からないのですが…
とりあえず、syncdb をやり直しただけでは同じエラーが返りました。

よろしくお願い致します。


On 8月16日, 午後6:52, Yoichi Fujimoto <woz...@gmail.com> wrote:
> syncdb した後にモデル弄って、テーブルのカラムが無いとかそんな感じっぽいので、
> drop table してから syncdb やり直すとどうでしょう。
>
> 2010/8/16 Hajime Fujita <hajime.fuj...@gmail.com>:

Yoichi Fujimoto

unread,
Aug 16, 2010, 6:54:06 AM8/16/10
to djan...@googlegroups.com
syncdb はモデルの変更を追従してくれないので、
一旦テーブルを削除してから syncdb してみたらどうでしょうか。


2010/8/16 Hajime Fujita <hajime...@gmail.com>:

Hajime Fujita

unread,
Aug 16, 2010, 7:58:43 AM8/16/10
to django-ja
藤田です。

通りました!

なぜエラーが解消したのかがいまいちよく分かってませんが、
データベース関連でエラーが出たときは、とりあえずテーブルを削除してみる
…ということを次から試したいと思います。

ありがとうございました。


On 8月16日, 午後7:54, Yoichi Fujimoto <woz...@gmail.com> wrote:
> syncdb はモデルの変更を追従してくれないので、
> 一旦テーブルを削除してから syncdb してみたらどうでしょうか。
>
> 2010/8/16 Hajime Fujita <hajime.fuj...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages