http://www.sqlalchemy.org/docs/05/ormtutorial.html

2 views
Skip to first unread message

paulo

unread,
Sep 3, 2009, 12:45:28 AM9/3/09
to sqlalchemy
Im trying to run through this tutorial http://www.sqlalchemy.org/docs/05/ormtutorial.html.

After running.

>>> from sqlalchemy.ext.declarative import declarative_base

>>> Base = declarative_base()
>>> class User(Base):
... __tablename__ = 'users'
...
... id = Column(Integer, primary_key=True)
... name = Column(String)
... fullname = Column(String)
... password = Column(String)
...
... def __init__(self, name, fullname, password):
... self.name = name
... self.fullname = fullname
... self.password = password
...
... def __repr__(self):
... return "<User('%s','%s', '%s')>" % (self.name,
self.fullname, self.password)

I got an error.

Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.5-
py2.6.egg/sqlalchemy/ext/declarative.py", line 546, in __init__
_as_declarative(cls, classname, dict_)
File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.5-
py2.6.egg/sqlalchemy/ext/declarative.py", line 539, in _as_declarative
cls.__mapper__ = mapper_cls(cls, table, properties=our_stuff,
**mapper_args)
File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.5-
py2.6.egg/sqlalchemy/orm/__init__.py", line 749, in mapper
return Mapper(class_, local_table, *args, **params)
File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.5-
py2.6.egg/sqlalchemy/orm/mapper.py", line 198, in __init__
self._configure_pks()
File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.5-
py2.6.egg/sqlalchemy/orm/mapper.py", line 439, in _configure_pks
"key columns for mapped table '%s'" % (self,
self.mapped_table.description))
ArgumentError: Mapper Mapper|User|users could not assemble any primary
key columns for mapped table 'users'


Any ideas why this happens?

rgds,
Paulo

Michael Bayer

unread,
Sep 3, 2009, 10:41:11 AM9/3/09
to sqlal...@googlegroups.com
not much idea. I'd make sure its not iPython screwing things up, I seem
to recall people having issues with it for some reason (which of course
seems ridiculous....)

Mike Conley

unread,
Sep 3, 2009, 11:10:23 AM9/3/09
to sqlal...@googlegroups.com
Any chance this is the second iteration of declaring the User class in this session, and the first time was missing the primary_key?

I run into this in interactive sessions and need to call  clear_mappers()  before redoing the class. It seems that the old mapper is still hanging around and causes the compilation error.

--
Mike Conley


Paulo Aquino

unread,
Sep 3, 2009, 11:35:32 AM9/3/09
to sqlal...@googlegroups.com
I guess it's ipython cause when I tried saving the tutorial source code in a file and run python xxxx.py everything
is working fine. Yeah you're right seems ridiculous. :)
Reply all
Reply to author
Forward
0 new messages