Have you tried changing the order so that Card is defined before 
collection_cards? Obviously you're passing 'cards.id' as a string so that the 
order doesn't matter, but have you tried it anyway?


-----Original Message-----
From: [email protected] [mailto:[email protected]] On 
Behalf Of Stefan Urbanek
Sent: Thursday, 9 February 2012 10:07 AM
To: sqlalchemy
Subject: [sqlalchemy] When creating many-to-many relationship I get: 
NoReferencedTableError

Hi,

I am trying to create a simple many-to-many relationship using
PostgreSQL in a specific schema ('cards'). I do it like this:

class BaseObject(object):
    id =  Column(Integer, primary_key=True)
    date_created = Column(DateTime)
    date_modified = Column(DateTime)

collection_cards = Table(
    'collection_cards', Base.metadata,
    Column('card_id', Integer, ForeignKey('cards.id')),
    Column('collection_id', Integer, ForeignKey('collections.id'))
    )

class Card(Base, BaseObject):
    __tablename__ = 'cards'

    content = Column(Text)

    def __init__(self):
        super(Card, self).__init__()

class Collection(BaseObject, Base):
    __tablename__ = 'collections'

    name = Column(String)

    def __init__(self):
        super(Collection, self).__init__()

    cards = relationship(Card, secondary=collection_cards)

...


Base.metadata.schema = "cards"
Base.metadata.create_all(engine)

and I get:

sqlalchemy.exc.NoReferencedTableError: Foreign key associated with
column 'collection_cards.card_id' could not find table 'cards' with
which to generate a foreign key to target column 'id'

Without the relationsip, the two tables are created just fine in the
specified schema. What I am doing wrong?

Thanks,

Stefan

-- 
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.



-------------------------------------------------------------------------
DISCLAIMER: This e-mail transmission and any documents, files and 
previous e-mail messages attached to it are private and confidential.  
They may contain proprietary or copyright material or information that 
is subject to legal professional privilege.  They are for the use of 
the intended recipient only.  Any unauthorised viewing, use, disclosure, 
copying, alteration, storage or distribution of, or reliance on, this 
message is strictly prohibited.  No part may be reproduced, adapted or 
transmitted without the written permission of the owner.  If you have 
received this transmission in error, or are not an authorised recipient, 
please immediately notify the sender by return email, delete this 
message and all copies from your e-mail system, and destroy any printed 
copies.  Receipt by anyone other than the intended recipient should not 
be deemed a waiver of any privilege or protection.  Thales Australia 
does not warrant or represent that this e-mail or any documents, files 
and previous e-mail messages attached are error or virus free.  

-------------------------------------------------------------------------

-- 
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.

Reply via email to