On Jan 6, 2012, at 2:23 PM, Adam Tauno Williams wrote:
> I'm updating my code to work with 0.7.4; and I have a class that is derived
> from two tables. I'm looking at
> <http://www.sqlalchemy.org/docs/orm/mapper_config.html#mapping-a-class-against-multiple-tables>
> but I'm not having any luck. When I try to operate on the database the
> first time it dies with an exception ending in -
>
> sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize
> - can't proceed with initialization of other mappers. Original exception
> was: Class <class 'coils.foundation.alchemy.task.TaskAction'> does not have a
> mapped column named 'job_id
>
> Which I guess I just don't understand. Any pointers would be appreciated
Sorry, this is not enough information. You haven't given me KVC or Contact so
I cannot reproduce. Here is a test case with as much info as you have here,
runs fine (below). If you can attach a fully reproducing .py script with all
requisite areas we can identify at what point you're referring to "job_id" from
the TaskAction table, which isn't really specified here (note TaskAction
doesn't have job_id since you've redefined it as "task_id").
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
Base= declarative_base()
metadata = Base.metadata
from sqlalchemy import *
import sqlalchemy.orm as orm
class Contact(Base):
__tablename__ = 'contact'
object_id = Column(Integer, primary_key=True)
history_table = Table( 'job_history', metadata,
Column('job_history_id', Integer,
Sequence('key_generator'), primary_key=True),
Column('job_id', Integer),
Column('actor_id', Integer,
ForeignKey(Contact.object_id), nullable=False),
Column('action', String),
Column('action_date', DateTime),
Column('job_status', String),
Column('db_status', String) )
info_table = Table( 'job_history_info', metadata,
Column('job_history_info_id', Integer,
Sequence('key_generator'), primary_key=True),
Column('comment', String),
Column('job_history_id', Integer,
ForeignKey('job_history.job_history_id')),
Column('db_status', String) )
history_and_info = join(history_table, info_table)
class TaskAction(Base):
""" An OpenGroupare Task History Info entry """
__table__ = history_and_info
db_status = orm.column_property(history_table.c.db_status,
info_table.c.db_status)
object_id = orm.column_property(history_table.c.job_history_id,
info_table.c.job_history_id)
task_id = history_table.c.job_id
task_status = history_table.c.job_status
action_date = history_table.c.action_date
actor_id = history_table.c.actor_id
comment = info_table.c.comment
configure_mappers()
s = Session()
print s.query(TaskAction)
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
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.