Thanks for the answers. I've tried what Christoph told, but returns the same error. What I'm trying now is to override that column to be a DateTime type because in this case SQLAlchemy doesn't give me any errors, so I think you are right Michael, is because of the driver. Can tell me how to override this column so that SQLAlchemy can see it as a datetime. I have tried this, I do not know if this is correct or not:
email_table = Table('email', metadata, Column('last_modified', DateTime()), autoload=True) Thanks again, Roberto Zapata On Jul 13, 10:14 am, Michael Bayer <[EMAIL PROTECTED]> wrote: > i cant reproduce that on this end. created the tables, inserted a > row into each, script returns fine (note its using a long value, i > thought that might be an issue, but its not). make sure youre on the > latest MySQLDB driver. also not sure if an older MySQL might be > problematic as well here (though i doubt it, its a very basic example). > > On Jul 13, 2007, at 9:53 AM, robertz23 wrote: > > > > > Hi, I've been using SQLAlchemy since a month. I'm having some > > problems with a one-to-many relationship. I have 2 tables: one for > > users and one for users's emails. The problem arises when I want to > > put a timestamp in the email table in order to see when a given > > account was created. Here are the tables, my code, and the error: > > > User Table: > > CREATE TABLE `user` ( > > `id` int(11) NOT NULL auto_increment, > > `name` varchar(100) NOT NULL, > > PRIMARY KEY (`id`) > > ) ENGINE=InnoDB DEFAULT CHARSET=latin1 > > > Email Table: > > CREATE TABLE `email` ( > > `id` int(11) NOT NULL auto_increment, > > `email` varchar(100) default NULL, > > `user_id` int(11) NOT NULL, > > `last_modified` timestamp NOT NULL default CURRENT_TIMESTAMP on > > update CURRENT_TIMESTAMP, > > PRIMARY KEY (`id`), > > KEY `fk_user_id` (`user_id`), > > CONSTRAINT `fk_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` > > (`id`) > > ) ENGINE=InnoDB DEFAULT CHARSET=latin1 > > > ##########CODE############ > > > user_table = Table('user', metadata, autoload=True) > > email_table = Table('email', metadata, autoload=True) > > class User(object): > > pass > > class Email(object): > > pass > > session_context = SessionContext(create_session) > > assign_mapper(session_context, User, user_table, > > properties={'emails':relation(Email)}) > > assign_mapper(session_context, Email, email_table) > > > obj = User() > > obj.get(1).emails > > > Traceback (most recent call last): > > File "<stdin>", line 1, in ? > > File "/usr/lib/python2.3/site-packages/sqlalchemy/orm/ > > attributes.py", line 53, in __get__ > > return self.get(obj) > > File "/usr/lib/python2.3/site-packages/sqlalchemy/orm/ > > attributes.py", line 217, in get > > values = callable_() > > File "/usr/lib/python2.3/site-packages/sqlalchemy/orm/ > > strategies.py", line 222, in lazyload > > result = session.query(self.mapper, > > with_options=options).select_whereclause(self.lazywhere, > > order_by=order_by, params=params) > > File "/usr/lib/python2.3/site-packages/sqlalchemy/orm/query.py", > > line 309, in select_whereclause > > return self._select_statement(statement, params=params) > > File "/usr/lib/python2.3/site-packages/sqlalchemy/orm/query.py", > > line 798, in _select_statement > > return self.execute(statement, params=params, **kwargs) > > File "/usr/lib/python2.3/site-packages/sqlalchemy/orm/query.py", > > line 694, in execute > > result = self.session.execute(self.mapper, clauseelement, > > params=params) > > File "/usr/lib/python2.3/site-packages/sqlalchemy/orm/session.py", > > line 183, in execute > > return self.connection(mapper, > > close_with_result=True).execute(clause, params, **kwargs) > > File "/usr/lib/python2.3/site-packages/sqlalchemy/engine/base.py", > > line 444, in execute > > return Connection.executors[c](self, object, *multiparams, > > **params) > > File "/usr/lib/python2.3/site-packages/sqlalchemy/engine/base.py", > > line 484, in execute_clauseelement > > return self.execute_compiled(elem.compile(engine=self.__engine, > > parameters=param), *multiparams, **params) > > File "/usr/lib/python2.3/site-packages/sqlalchemy/engine/base.py", > > line 503, in execute_compiled > > proxy(str(compiled), parameters) > > File "/usr/lib/python2.3/site-packages/sqlalchemy/engine/base.py", > > line 499, in proxy > > self._execute_raw(statement, parameters, cursor=cursor, > > context=context) > > File "/usr/lib/python2.3/site-packages/sqlalchemy/engine/base.py", > > line 547, in _execute_raw > > self._execute(cursor, statement, parameters, context=context) > > File "/usr/lib/python2.3/site-packages/sqlalchemy/engine/base.py", > > line 566, in _execute > > raise exceptions.SQLError(statement, parameters, e) > > sqlalchemy.exceptions.SQLError: (ValueError) invalid literal for > > int(): 7- 'SELECT email.last_modified AS email_last_modified, > > email.user_id AS email_user_id, email.id AS email_id, email.email AS > > email_email \nFROM email \nWHERE %s = email.user_id ORDER BY > > email.id' [1L] > > > Sorry for putting too much data, but I'm a little desperate, I've > > been trying to do this for a whole week and I can't find useful > > information about this error. I only found that this exception is > > when a query is not very well formed or something like that. Please > > help me as soon as you can, thanks in advance for reading this post. > > > regards, > > Roberto Zapata --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---