Dear list I'm new to sqlalchemy and so far, I am very impressed. I was able to install SQLalchemy in about two minutes or so :-) and at the moment, I am trying to follow the steps in the documentation.
I started with three tables (shown below) and tried to save a user in the database using the information in http://www.sqlalchemy.org/docs/05/ormtutorial.html#adding-new-objects I'm getting the following error caused by the last line in my script: localhost:squirrel michael$ python squirrel.py Traceback (most recent call last): File "squirrel.py", line 47, in <module> our_user = session.query(User).filter_by(login='ed').first() File "/Library/Python/2.5/site-packages/SQLAlchemy-0.4.8-py2.5.egg/ sqlalchemy/orm/query.py", line 909, in first ret = list(self[0:1]) File "/Library/Python/2.5/site-packages/SQLAlchemy-0.4.8-py2.5.egg/ sqlalchemy/orm/query.py", line 937, in __iter__ self.session._autoflush() File "/Library/Python/2.5/site-packages/SQLAlchemy-0.4.8-py2.5.egg/ sqlalchemy/orm/session.py", line 771, in _autoflush self.flush() File "/Library/Python/2.5/site-packages/SQLAlchemy-0.4.8-py2.5.egg/ sqlalchemy/orm/session.py", line 789, in flush self.uow.flush(self, objects) File "/Library/Python/2.5/site-packages/SQLAlchemy-0.4.8-py2.5.egg/ sqlalchemy/orm/unitofwork.py", line 237, in flush flush_context.execute() File "/Library/Python/2.5/site-packages/SQLAlchemy-0.4.8-py2.5.egg/ sqlalchemy/orm/unitofwork.py", line 449, in execute UOWExecutor().execute(self, tasks) File "/Library/Python/2.5/site-packages/SQLAlchemy-0.4.8-py2.5.egg/ sqlalchemy/orm/unitofwork.py", line 934, in execute self.execute_save_steps(trans, task) File "/Library/Python/2.5/site-packages/SQLAlchemy-0.4.8-py2.5.egg/ sqlalchemy/orm/unitofwork.py", line 949, in execute_save_steps self.save_objects(trans, task) File "/Library/Python/2.5/site-packages/SQLAlchemy-0.4.8-py2.5.egg/ sqlalchemy/orm/unitofwork.py", line 940, in save_objects task.mapper._save_obj(task.polymorphic_tosave_objects, trans) File "/Library/Python/2.5/site-packages/SQLAlchemy-0.4.8-py2.5.egg/ sqlalchemy/orm/mapper.py", line 1008, in _save_obj connection = uowtransaction.transaction.connection(self) File "/Library/Python/2.5/site-packages/SQLAlchemy-0.4.8-py2.5.egg/ sqlalchemy/orm/session.py", line 178, in connection return self.get_or_add(engine) File "/Library/Python/2.5/site-packages/SQLAlchemy-0.4.8-py2.5.egg/ sqlalchemy/orm/session.py", line 208, in get_or_add conn = self._parent.get_or_add(bind) File "/Library/Python/2.5/site-packages/SQLAlchemy-0.4.8-py2.5.egg/ sqlalchemy/orm/session.py", line 217, in get_or_add conn = bind.contextual_connect() AttributeError: 'MetaData' object has no attribute 'contextual_connect' Could anyone tell me why this is happening? Here's my complete code I've used: from sqlalchemy import * from datetime import datetime import sys metadata = MetaData('sqlite:///squirrel.db') user_table = Table( 'user', metadata, Column('id', Integer, primary_key=True), Column('login', Unicode(25), nullable=False), Column('password', Unicode(40), nullable=False) ) person_table = Table( 'person', metadata, Column('id', Integer, primary_key=True), Column('firstname', Unicode(25)), Column('lastname', Unicode(25)), Column('birthday', DateTime) ) person_user = Table( 'person_user', metadata, Column('id', Integer, primary_key=True), Column('person_id', Integer, ForeignKey('person.id')) ) metadata.create_all() class User(object): def __init__(self, login, password): self.login = login self.password = password def __repr__(self): return "<User('%s', '%s')>" % (self.login, self.password) from sqlalchemy.orm import mapper mapper(User, user_table) from sqlalchemy.orm import sessionmaker Session = sessionmaker(bind=metadata) session = Session() ed_user = User('ed', 'password of ed') session.add(ed_user) our_user = session.query(User).filter_by(login='ed').first() --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---