-1

这个问题基于线程,因为我观察到 Storm 允许我重用我的 SQL 模式。

如何解决 Storm 中的以下错误消息?

该代码基于 Jason 的回答和 Storm 的手册。

import os, pg, sys, re, psycopg2, storm
from storm.locals import *
from storm import *

class Courses():
    subject = Unicode()

database = create_database("postgres://naa:123@localhost:5432/tk")
store = Store(database)

course = Courses()
course.subject = 'abcd'
store.add(course)

它给你

Traceback (most recent call last):                                            
  File "<stdin>", line 13, in <module>
  File "/usr/lib/python2.6/dist-packages/storm/store.py", line 245, in add
    obj_info = get_obj_info(obj)
  File "/usr/lib/python2.6/dist-packages/storm/info.py", line 40, in get_obj_info 
    obj_info = ObjectInfo(obj)
  File "/usr/lib/python2.6/dist-packages/storm/info.py", line 162, in __init__
    self.cls_info = get_cls_info(type(obj))
  File "/usr/lib/python2.6/dist-packages/storm/info.py", line 51, in get_cls_info
    cls.__storm_class_info__ = ClassInfo(cls)
  File "/usr/lib/python2.6/dist-packages/storm/info.py", line 69, in __init__
    raise ClassInfoError("%s.__storm_table__ missing" % repr(cls))
storm.exceptions.ClassInfoError: <type 'instance'>.__storm_table__ missing

这向我表明缺少某些模块。Storm中没有模块instance

4

1 回答 1

4

我将省略连接细节,因为我对 Postgres 不是很熟悉。

from storm.locals import *

class Courses(object):
    __storm_table__ = 'courses'
    pkey = Int(primary=True)
    course_nro = Unicode()

course = Courses()
course.course_nro = 'abcd'
store.add(course)
store.commit()

当然,如果你想在一行中做构造函数和初始化,你可以使用pysistenceexpandos

from storm.locals import *
from pysistence import Expando

class Courses(Expando):
    __storm_table__ = 'courses'
    pkey = Int(primary=True)
    course_nro = Unicode()

course = Courses(course_nro='abcd')
store.add(course)
store.commit()
于 2009-11-22T19:57:41.733 回答