Noufal wrote:
> Hello everyone,
>   I've recently picked up SQLAlchemy for a project that I'm working
> on. I couldn't get a version newer than 0.3.10 (admin bureaucracy) and
> have to use this.
> 
>   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'"
> 
> Am I doing something wrong or is there something else wrong here? If
> it's a bug that's been fixed in later versions, is there some kind of
> a workaround I could use?

Did you originally create the tables through SQLAlchemy or are you 
reflecting an existing schema?  In either case I'd need to see the 
output of SHOW CREATE TABLES for the problem table to make a diagnosis.

You can workaround this by manually adding a FK after autoloading:

   stats_table.append_constraint(
     sa.ForeignKeyConstraint(['rid'], ['runs.rid']))



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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