I am trying to go through the mapping tutorial in 0.4.2p3 for
association objects. I get an error about "Could not assemble any
primary key columns for mapped table 'association'" when attempting to
map the association table itself. This is straight out of the Mapping
Configuration docs that comes with the distribution...
Any thoughts on where things are going awry?
Here's my complete code:
from sqlalchemy import create_engine, \
Table, Column, Integer, String, \
MetaData, ForeignKey
from sqlalchemy.orm import relation, sessionmaker, mapper
engine = create_engine('sqlite:///:memory:', echo=True)
metadata = MetaData();
left_table = Table('left', metadata,
Column('id', Integer, primary_key=True))
right_table = Table('right', metadata,
Column('id', Integer, primary_key=True))
association_table = Table('association', metadata,
Column('left_id', Integer, ForeignKey('left.id')),
Column('right_id', Integer, ForeignKey('right.id')),
Column('data', String(50))
)
class Parent(object): pass
class Association(object): pass
class Child(object): pass
mapper( Parent, left_table, properties={
'children':relation(Association)
})
mapper( Association, association_table, properties={
'child':relation(Child) # <--- chokes here
})
mapper( Child, right_table)
metadata.create_all( engine )
And here is what I get:
$ python -i posting.py
Traceback (most recent call last):
File "posting.py", line 31, in <module>
'child':relation(Child) # <--- chokes here
File "/tmp/SQLAlchemy-0.4.2p3/lib/sqlalchemy/orm/__init__.py", line
544, in mapper
return Mapper(class_, local_table, *args, **params)
File "/tmp/SQLAlchemy-0.4.2p3/lib/sqlalchemy/orm/mapper.py", line
160, in __init__
self._compile_pks()
File "/tmp/SQLAlchemy-0.4.2p3/lib/sqlalchemy/orm/mapper.py", line
428, in _compile_pks
raise exceptions.ArgumentError("Could not assemble any primary key
columns for mapped table '%s'" % (self.mapped_table.name))
sqlalchemy.exceptions.ArgumentError: Could not assemble any primary
key columns for mapped table 'association'
>>>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---