Noufal wrote:
> <snip>
> 
>   I create two tables like so
>         run_table = sa.Table('runs',md,
>                              sa.Column('rid', sa.Integer,
> primary_key=True),
>                              sa.Column('cmdline', sa.String(250)),
>                              sa.Column('hostname', sa.String(20)),
>                              sa.Column('workdir', sa.String(250)),
>                              sa.Column('incremental', sa.Boolean),
>                              sa.Column('user', sa.String(20)),
>                              sa.Column('starttime', sa.TIMESTAMP),
>                              sa.Column('endtime', sa.TIMESTAMP),
>                              sa.Column('status',sa.String(20)),
>                              sa.Column('machinetype',sa.String(20))
>                              )
>         run_table.create()
> 
>         stats_table = sa.Table('stats',md,
>  
> sa.Column('sid',sa.Integer,primary_key=True),
>  
> sa.Column('rid',sa.Integer,sa.ForeignKey('runs.rid')),
>                                sa.Column('stagename',sa.String(50)),
>  
> sa.Column('description',sa.String(250)),
>                                sa.Column('starttime',sa.TIMESTAMP),
>                                sa.Column('endtime',sa.TIMESTAMP))
>         stats_table.create()
> 
> Then I can actually use these tables.
> However, if I autoload them like so.
>    run_table = sa.Table('runs', md, autoload=True)
>    stats_table = sa.Table('stats', md, autoload=True)
> (md is the metadata)
> I get an error. The final assertion raised is like so
> 
> sqlalchemy.exceptions.ArgumentError: Error determining primary and/or
> secondary join for relationship 'Run.stages (Stats)'. 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 the join conditions. Nested
> error is "Can't find any foreign key relationships between 'runs' and
> 'stats'"
> 
> <snip>

The table reflection doesn't seem to be picking up the foreign key
definition from stats.rid to runs.rid. In 0.3.10, SA uses a regular
expression on the output of 'SHOW CREATE TABLE' to find foreign keys
(round about line 1169 of databases/mysql.py). You could run 'SHOW
CREATE TABLE stats' yourself and try and figure out why the regular
expression isn't matching.

<http://www.sqlalchemy.org/trac/browser/sqlalchemy/tags/rel_0_3_10/lib/s
qlalchemy/databases/mysql.py#L1169>

However, you can provide your own foreign key definition while still
autoloading the table. Something like this should work:

stats_table = sa.Table('stats', md,
                       sa.ForeignKeyConstraint(['stats.rid'],
['runs.rid']),
                       autoload=True)

Also, I believe mysql table reflection is being completely reworked in
0.4, so the issue might go away.

Hope that helps,

Simon

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