[sqlalchemy] Re: Copy of a table with a different name
send along a test case that includes whatever ForeignKey references to/ from ObjectType might be involved here. My initial guess might be to lose the constraints.copy() section since each Column.copy() will contain a copied ForeignKey inside of it. copy() has only been used by the to_metadata() method up til this point. Sorry for not replying for a month. I'm trying to produce a test case using simple tables. I use two MetaDatas but what I get is sqlalchemy.exceptions.NoReferencedTableError: Could not find table 'A' with which to generate a foreign key In production code I use foreign keys between tables in different metadatas (I use one MetaData per component). Is it ok and should work? Here is the complete code: #!/usr/bin/python from sqlalchemy import Table, Column, Integer, Text, MetaData, ForeignKey, Date, DateTime, Float from sqlalchemy.engine import create_engine from sqlalchemy.orm import mapper, relation, backref engine = create_engine('sqlite://') metadata_1 = MetaData() metadata_2 = MetaData() def _cloneToSND(table, metadata): return Table('SND_' + table.name, metadata, *([c.copy() for c in table.columns] + \ [c.copy() for c in table.constraints])) tableA = Table('A', metadata_1, Column('id', Integer, primary_key=True)) tableB = Table('B', metadata_1, Column('id', Integer, primary_key=True), Column('a_id', Integer, ForeignKey(tableA.c.id), nullable=True, index=True)) tableC = Table('C', metadata_2, Column('id', Integer, primary_key=True), Column('a_id', Integer, ForeignKey(tableA.c.id), nullable=True, index=True)) #Column('b_id', Integer, ForeignKey(tableB.c.id), nullable=True, index=True)) tableSND_A = _cloneToSND(tableA, metadata_1) tableSND_B = _cloneToSND(tableB, metadata_1) tableSND_C = _cloneToSND(tableC, metadata_2) if __name__ == '__main__': metadata_1.create_all(bind=engine) metadata_2.create_all(bind=engine) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] correlated update across logical databases
Hi I would like to do a correlated update involving tables located in two logical databases on the same MySQL server. The commented out code below would work except that the mysql ends up looking for the one table in the wrong database. customer is defined as Table('customer', ps_final_meta, autoload=True) and sdf_customer is defined as Table('sdf_customer, ps_staging_meta, autoload=True). How can I tell sqlalchemy to include the database names in the sql it generates? For the moment I am just using SQL directly in an execute(). file_ids_str = makeSQLList(tuple(file_ids)) # sqlalchemy correlated update # TODO: figure out to do correlated updates across databases # #s = select([customer.c.MP_Code], # and_(customer.c.CustomerAccNo1==sdf_customer.c.CustomerAccNo1, #customer.c.WholesalerID==sdf_customer.c.WholesalerID # )).limit(1) #rc = sdf_customer.update( # and_(sdf_customer.c.StatusID.in_([8, 12]), #sdf_customer.c.FileID.in_(file_ids) # ), # values={sdf_customer.c.MP_Code:s}).execute().rowcount sql = update sdf_customer set sdf_customer.MP_Code = ( select fc.MP_Code from ps_final.customer fc where sdf_customer.CustomerAccNo1=fc.CustomerAccNo1 and sdf_customer.WholesalerID=fc.WholesalerID) where sdf_customer.StatusID in (8, 12) and sdf_customer.FileID in %s % (file_ids_str,) rc = dbengine.execute(sql).rowcount Any help would be much appreciated. Regards, Ryan -- Ryan Tracey Citizen: The World --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: correlated update across logical databases
On Jul 17, 2008, at 7:12 AM, Ryan Tracey wrote: Hi I would like to do a correlated update involving tables located in two logical databases on the same MySQL server. The commented out code below would work except that the mysql ends up looking for the one table in the wrong database. customer is defined as Table('customer', ps_final_meta, autoload=True) and sdf_customer is defined as Table('sdf_customer, ps_staging_meta, autoload=True). How can I tell sqlalchemy to include the database names in the sql it generates? For the moment I am just using SQL directly in an execute(). file_ids_str = makeSQLList(tuple(file_ids)) # sqlalchemy correlated update # TODO: figure out to do correlated updates across databases # #s = select([customer.c.MP_Code], # and_(customer.c.CustomerAccNo1==sdf_customer.c.CustomerAccNo1, # customer.c.WholesalerID==sdf_customer.c.WholesalerID # )).limit(1) #rc = sdf_customer.update( # and_(sdf_customer.c.StatusID.in_([8, 12]), #sdf_customer.c.FileID.in_(file_ids) # ), # values={sdf_customer.c.MP_Code:s}).execute().rowcount sql = update sdf_customer set sdf_customer.MP_Code = ( select fc.MP_Code from ps_final.customer fc where sdf_customer.CustomerAccNo1=fc.CustomerAccNo1 and sdf_customer.WholesalerID=fc.WholesalerID) where sdf_customer.StatusID in (8, 12) and sdf_customer.FileID in %s % (file_ids_str,) rc = dbengine.execute(sql).rowcount OK, you have two MetaData objects which makes me think each one has its own engine pointing to an environment with a particular default schema. If you'd like one SQL statement to be generated, referencing tables in both schemas and executeable within a single environment, all the Table objects need to be defined in terms of one default schema. Those which are in a different schema should include the Table keyword argument schema='somename'. You should get the whole thing working using just one Engine and one MetaData object which contains all tables. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Data Inheritance
On Jul 16, 2008, at 3:29 PM, laureano arcanio wrote: Hi, I'm planning to implement Data inheritance for an os project i'm working on [1]. I have a model with a few tables and relationships between them ( not a complicated stuff ) and i was wandering if there is a way to accomplish data inheritance in an automated way ( i can eventually make a script to accomplish this ) I mind, given a Parent id, I'd like to copy it and get all child copied and modified too. Does it possible ? if not, i will be manually doing it.. just making the whole model introspection by hand.. ( grr ) Any light on it would by great ! ( I'm having problems to explain on English what I'm trying to do. sorry about it) The general forms of table inheritance that SQLAlchemy supports directly are described here: http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_mapper_inheritance . --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: subclassing Table
On Jul 16, 2008, at 4:43 PM, Tamas wrote: Hi, I am not a professional coder; hobby-like thing. I would like to encapsulate my table definitions in a new class: class MyTable( Table): def __init__( self, metadata): Table.__init__( self, my_table_name, metadata, col1, col2...) metadata = MetaData() table = MyTable( metadata) Traceback (most recent call last): File create_tables.py, line 11, in module table = MyTable( metadata) TypeError: __call__() takes at least 3 arguments (2 given) *** I tested different things and I have the feeling that it is not possible to subclass the Table class. Is this true? If no: what is the mistake I make? If yes: why? does Table class have some special decoration or something like that? How do you avoid to define your table in every script you write to use that table with its corresponding class? its possible, but tricky since the creation of a Table is routed through a metaclass which ensures that only one instance of Table for a particular name within the MetaData exists, i.e.: - t1 = Table('t1', metadata, ...) - t2 = Table('t1', metadata, ...) - t1 is t2 True So true subclassing here would require that you also subclass the metaclass to do what you want here, which is probably not a good idea since thats not public API stuff. If its just a creational pattern you're looking for, I'd suggest using a def instead of a class: def MyTable(metadata): return Table('myname', metadata, ...) If there's other behavior you're looking for, let us know what it is and we'll see if we can accomodate you. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: subclassing Table
Thanks a lot! I think your suggestion will be ok for me for now. Have a good day, tamas On Thu, Jul 17, 2008 at 9:55 AM, Michael Bayer [EMAIL PROTECTED] wrote: On Jul 16, 2008, at 4:43 PM, Tamas wrote: Hi, I am not a professional coder; hobby-like thing. I would like to encapsulate my table definitions in a new class: class MyTable( Table): def __init__( self, metadata): Table.__init__( self, my_table_name, metadata, col1, col2...) metadata = MetaData() table = MyTable( metadata) Traceback (most recent call last): File create_tables.py, line 11, in module table = MyTable( metadata) TypeError: __call__() takes at least 3 arguments (2 given) *** I tested different things and I have the feeling that it is not possible to subclass the Table class. Is this true? If no: what is the mistake I make? If yes: why? does Table class have some special decoration or something like that? How do you avoid to define your table in every script you write to use that table with its corresponding class? its possible, but tricky since the creation of a Table is routed through a metaclass which ensures that only one instance of Table for a particular name within the MetaData exists, i.e.: - t1 = Table('t1', metadata, ...) - t2 = Table('t1', metadata, ...) - t1 is t2 True So true subclassing here would require that you also subclass the metaclass to do what you want here, which is probably not a good idea since thats not public API stuff. If its just a creational pattern you're looking for, I'd suggest using a def instead of a class: def MyTable(metadata): return Table('myname', metadata, ...) If there's other behavior you're looking for, let us know what it is and we'll see if we can accomodate you. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Session query timeout
Hi all, I'm using SQLAlchemy to access a large table (~280 million rows), and I'm getting timeout issues. At 30 seconds, SQLAlchemy quits. In lieu of getting all tables past and future to be indexed differently, I was wondering if there was a way using session.query (*not* select()) to change the default timeout of 30 seconds to something more suitable for such large tables. All I have found on the web points to QueuePool and the pool_timeout parameter, but it is unclear as to how this fits in with a mapper and session.query. Here is a snippet of the code I am using: def createSession(): global session, table1 engine = create_engine('mssql://database', echo=False) metadata = MetaData() metadata.bind=engine table1 = Table('Large Table', metadata,\ Column('LocationId',Integer,primary_key=True), autoload=True) mymapper1=mapper(Object,table1) Session = sessionmaker(bind=engine, autoflush=True, transactional=True) session = Session() def getData(lmplocation_id): global session, table1 if not session: createSession() result = session.query(Object) return result Thanks, Chris --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Data Inheritance
Thanks Michael. I might not explain it well, but I've traying to make some kind of data ( rows ) inheritance, this is copying a table value and all it's related childrens, and modify it as necesary with new values in an automated way. ( not inherit Table structures ) It's looks weird i think, I'll acomplish some similar stuff mannually beacause i dont think this already exists, if it does i could not fint anything like this. Thanks for your help. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Session query timeout
On Jul 17, 2008, at 9:24 AM, Chris wrote: Hi all, I'm using SQLAlchemy to access a large table (~280 million rows), and I'm getting timeout issues. At 30 seconds, SQLAlchemy quits. In lieu of getting all tables past and future to be indexed differently, I was wondering if there was a way using session.query (*not* select()) to change the default timeout of 30 seconds to something more suitable for such large tables. All I have found on the web points to QueuePool and the pool_timeout parameter, but it is unclear as to how this fits in with a mapper and session.query. Here is a snippet of the code I am using: def createSession(): global session, table1 engine = create_engine('mssql://database', echo=False) metadata = MetaData() metadata.bind=engine table1 = Table('Large Table', metadata,\ Column('LocationId',Integer,primary_key=True), autoload=True) mymapper1=mapper(Object,table1) Session = sessionmaker(bind=engine, autoflush=True, transactional=True) session = Session() def getData(lmplocation_id): global session, table1 if not session: createSession() result = session.query(Object) return result what database is this ? The timeout of the connection itself, or the max time allowed to spend on an execution is typically a specific setting within your client library. If its an argument to the DBAPI's connect() method, it can be passed through using the connect_args kwarg to create_engine() - though I usually see setting like these within the configuration files for the database itself. SQLA itself does not set any timeout parameters; we only have pool_recycle which is turned off by default, and only takes effect upon pool checkout for an otherwise unused connection. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Data Inheritance
On Thursday 17 July 2008 17:06:14 laureano arcanio wrote: Thanks Michael. I might not explain it well, but I've traying to make some kind of data ( rows ) inheritance, this is copying a table value and all it's related childrens, and modify it as necesary with new values in an automated way. ( not inherit Table structures ) It's looks weird i think, I'll acomplish some similar stuff mannually beacause i dont think this already exists, if it does i could not fint anything like this. i am not sure i understand what u want, but here's my baseDBclass.copy() method. [ sidenote: if u talk about real value inheritance/shading, that is different quite complex beast, i have that too. e.g. A.x, B.x are values, B.a points to some A, and Bs are before As in the value-inheritance chain, so if A1.x=2, B1.a=A1 and B1.x=5, then inherited( B1.x) = 5 (e.g. shading); while if B1.x has no value, then inherited( B1.x)= 2 (e.g. inheritance or see-through). ] here, i have objects with bitemporal versions, with bitemporal many2many associations for most relations, hence any new version is a semi-deep copy of previous + the modifications on top of that. u can use this below as pseudocode/starting point to write your own - plz ignore anything that makes no sense to you, or substitute with your stuff of same meaning if u have such. basicaly, logic is to copy all plain attributes and references, then walk all relations and copy those, with the special case of explicit associations, where the backlink of the copy of each member should be explicitly set to the new owner. Each item (plain or relation-member) is checked if it has to be depth-copied or not. class _NOTFOUND: pass class Struct( _Base, ): dont_copy = [] # set of attr-names to ignore when copying; #when inheriting dont miss the base set dont_copy_me = False#copy as reference, not in depth; # the copy wil refer same object def copy( me, dont_copy_now =()): if dbg: print l, 'copying', me new = me.__class__() #singulars done = set() for walker in [ me._walkTypes(), me._DBCOOK_references ]: for name in walker: if name in done: continue done.add( name) if name in dont_copy_now or name in me.dont_copy: if dbg: print l, ' ignore', name continue item = getattr( me, name, _NOTFOUND) if item is _NOTFOUND: #nothing to copy if dbg: print l, ' ignore/novalue', name continue i0 = item if not getattr( item, 'dont_copy_me', None): vcopy = getattr( item, 'copy', None) if callable( vcopy): if dbg: print l, ' copy-deep', name, item item = vcopy() if dbg: if i0 is item: print l, ' copy-ref', name print l, ' copied', name, '=', item setattr( new, name, item) #maybe rels = [ p in class_mapper(klas).props if p.uselist ] rels = getattr( me, '_DBCOOK_relations', () ) for name in rels: if name in dont_copy_now or name in me.dont_copy: if dbg: print l, ' ignore', name continue #make deep-copy of the set = set of copies of each item child_klas = rels[ name] if dbg: print l, ' copy-relation', name, ':', child_klas children = getattr( me, name) #XXX this can load all!! new_children = getattr( new, name) explicit_assoc=not getattr( child_klas, 'DBCOOK_hidden', True) ab = about_relation( me.__class__, name) attr = ab.otherside.name for a in children: #3 cases: non-assoc (nocopy), assoc.hidden (nocopy), # assoc.explicit:copy if explicit_assoc: if dbg: print ' copy-deep-assoc', a assert getattr( a, attr) is me a = a.copy( dont_copy_now= [attr] ) if ab.no_backref: if dbg: print ' replace', attr, new setattr( a, attr, new) else: if dbg: print ' copy-ref' if dbg: print ' copied-over', a new_children.append( a ) if dbg: print l, ' copied-relation', name, new_children return new --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at
[sqlalchemy] KeyError with SA 0.4.6 and Elixir 0.5.2
Hello all, I'm using SQLAlchemy 0.4.6 with Elixir 0.5.2 I'm having intermittent trouble when I've spread the Elixir classes across multiple files. In my example, I've declared classes in User.py -- class User(elixir.entity) Credential.py -- class Credential(elixir.entity) AccessGrant.py -- class AccessGrant(elixir.entity). and I import these in another file. SqlDB.py. when I try to instantiate SqlDB object, I get the error: File D:\RecogSys\src\python\RSITerm\SQLConvert\SqlDB.py, line 87, in initSetup elixir.setup_all(True) File d:\python24\lib\site-packages\elixir-0.5.2-py2.4.egg\elixir \__init__.py, line 117, in setup _all setup_entities(entities) File d:\python24\lib\site-packages\elixir-0.5.2-py2.4.egg\elixir \entity.py, line 753, in setup_e ntities method() File d:\python24\lib\site-packages\elixir-0.5.2-py2.4.egg\elixir \entity.py, line 191, in create_ pk_cols self.call_builders('create_pk_cols') File d:\python24\lib\site-packages\elixir-0.5.2-py2.4.egg\elixir \entity.py, line 436, in call_bu ilders getattr(builder, what)() File d:\python24\lib\site-packages\elixir-0.5.2-py2.4.egg\elixir \relationships.py, line 373, in create_pk_cols self.create_keys(True) File d:\python24\lib\site-packages\elixir-0.5.2-py2.4.egg\elixir \relationships.py, line 626, in create_keys if self.inverse is None: File d:\python24\lib\site-packages\elixir-0.5.2-py2.4.egg\elixir \relationships.py, line 455, in inverse inverse = self.target._descriptor.get_inverse_relation(self) File d:\python24\lib\site-packages\elixir-0.5.2-py2.4.egg\elixir \relationships.py, line 437, in target self._target = caller_entities[classname] KeyError: 'Credential' I dont know why this is happening. Any pointers? Why I say 'intermittent' is that the same configuration used to work earlier. thanks, Venkatesh. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Declarative 0.5 tutorial fails to create tables before insert
Hi, I'm trying to follow the declarative example in the tutorial with 0.5.0b2, and it's failing to work: from sqlalchemy import create_engine engine = create_engine('sqlite:///:memory:', echo=True) from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey 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) from sqlalchemy.orm import sessionmaker Session = sessionmaker(bind=engine) session = Session() ed_user = User('ed', 'Ed Jones', 'edspassword') session.add(ed_user) session.add_all([ User('wendy', 'Wendy Williams', 'foobar'), User('mary', 'Mary Contrary', 'xxg527'), User('fred', 'Fred Flinstone', 'blah')]) session.commit() --- Produces: pointyhat# python sqltest.py 2008-07-17 20:15:37,118 INFO sqlalchemy.engine.base.Engine.0x..e0 BEGIN 2008-07-17 20:15:37,121 INFO sqlalchemy.engine.base.Engine.0x..e0 INSERT INTO users (name, fullname, password) VALUES (?, ?, ?) 2008-07-17 20:15:37,121 INFO sqlalchemy.engine.base.Engine.0x..e0 ['ed', 'Ed Jones', 'edspassword'] 2008-07-17 20:15:37,122 INFO sqlalchemy.engine.base.Engine.0x..e0 ROLLBACK Traceback (most recent call last): File sqltest.py, line 37, in module session.commit() File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/session.py, line 649, in commit self.transaction.commit() File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/session.py, line 366, in commit self._prepare_impl() File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/session.py, line 350, in _prepare_impl self.session.flush() File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/session.py, line 1394, in flush flush_context.execute() File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/unitofwork.py, line 268, in execute UOWExecutor().execute(self, tasks) File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/unitofwork.py, line 754, in execute self.execute_save_steps(trans, task) File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/unitofwork.py, line 769, in execute_save_steps self.save_objects(trans, task) File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/unitofwork.py, line 760, in save_objects task.mapper._save_obj(task.polymorphic_tosave_objects, trans) File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/mapper.py, line 1163, in _save_obj c = connection.execute(statement.values(value_params), params) File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/engine/base.py, line 847, in execute return Connection.executors[c](self, object, multiparams, params) File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/engine/base.py, line 898, in execute_clauseelement return self._execute_compiled(elem.compile(dialect=self.dialect, column_keys=keys, inline=len(params) 1), distilled_params=params) File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/engine/base.py, line 910, in _execute_compiled self.__execute_raw(context) File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/engine/base.py, line 919, in __execute_raw self._cursor_execute(context.cursor, context.statement, context.parameters[0], context=context) File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/engine/base.py, line 963, in _cursor_execute self._handle_dbapi_exception(e, statement, parameters, cursor) File /usr/local/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/engine/base.py, line 945, in _handle_dbapi_exception raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect) sqlalchemy.exc.OperationalError: (OperationalError) no such table: users u'INSERT INTO users (name, fullname, password) VALUES (?, ?, ?)' ['ed', 'Ed Jones', 'edspassword'] i.e. it's failing to create the table before trying to insert into it. What is wrong? Kris --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy
[sqlalchemy] Re: Declarative 0.5 tutorial fails to create tables before insert
On Jul 17, 2008, at 4:44 PM, Kris Kennaway wrote: from sqlalchemy.orm import sessionmaker Session = sessionmaker(bind=engine) session = Session() ed_user = User('ed', 'Ed Jones', 'edspassword') session.add(ed_user) session.add_all([ User('wendy', 'Wendy Williams', 'foobar'), User('mary', 'Mary Contrary', 'xxg527'), User('fred', 'Fred Flinstone', 'blah')]) session.commit() you're missing a metadata.create_all() in there. From your declarative base call Base.metadata.create_all(engine). --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---