On Jun 22, 2007, at 11:37 AM, Inno wrote:
>
> Hi,
>
> I am trying to make deletes cascade from one table to another, but
> unfortunately the tables are in different databases.
>
> <code>
> metadata1 = BoundMetaData('mysql://host/db1')
> metadata2 = BoundMetaData('mysql://host/db2')
>
> jobs_table = Table('jobs', metadata1,
> Column('jobid', Integer, primary_key=True),
> autoload=True)
>
> folders_table = Table('folders', metadata2,
> Column('client', Integer, nullable=False),
> Column('account', String(8), nullable=False),
> ForeignKeyConstraint(['client', 'account'], ['jobs.client_id',
> 'jobs.account']),
> autoload=True)
>
> mapper(Job, jobs_table, properties = {'folder': relation(Folder,
> cascade="all, delete-orphan")} )
>
> session = create_session()
> job_query = session.query(Job)
> </code>
>
> The error I get is this:
> ArgumentError: Error determining primary and/or secondary join for
> relationship 'Job.folder (Folder)'. If the underlying error cannot be
> corrected, you should specify the 'primaryjoin' (and 'secondaryjoin',
> if there is an association table present) keyword arguments to the
> relation() function (or for backrefs, by specifying the backref using
> the backref() function with keyword arguments) to explicitly specify
foreign keys cant be created across MetaData objects. you need to
eitiher use primaryjoin like the error message says, or place all of
your Table objects, across all databases, into a single MetaData
object, then bind() individual mappers/tables to engines at the
session level (read the chapter on sessions for this).
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---