在问题基于线程时,因为我观察到风暴让我再利用我的SQL-模式。

你怎么能在风暴解决以下错误消息?

在代码是基于Jason的答案,并在风暴手册。

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

此建议,我认为某些模块被丢失。存在风暴没有模块instance

有帮助吗?

解决方案

我就离开了连接细节,因为我并不十分熟悉的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()

当然,如果你想要做的构造和初始化在同一行,你可以使用 pysistence expandos将

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()
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top