Making ORM with Python's Storm
Question: The question is based on [the
thread](http://stackoverflow.com/questions/1779239/converting-sql-commands-to-
pythons-orm), since I observed that Storm allows me reuse my SQL-schemas.

**How can you solve the following error message in Storm?**

The code is based on Jason's answer and on Storm's manual.

    
    
    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)
    

It gives you

    
    
    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
    

This suggests to me that some module is missing. There is no module `instance`
in Storm.


Answer: I'll leave out the connection details because I'm not terribly familiar with
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()
    

Of course, if you want to do the constructor and initialization on one line,
you can use [pysistence](http://packages.python.org/pysistence/index.html)'s
[expandos](http://packages.python.org/pysistence/pysistence/expando.html):

    
    
    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()
    

