I don't understand your model. Can you have multiple rows in the
Exchange table which all have the same value for Exchange.exchange?

If so, and if you want PhoneNumber to be able to point to a single one
of those rows, then it needs 2 columns to do that (one to point to
Exchange.exchange and one to point at Exchange.area_code_pk).

If not (ie. Exchange.exchange uniquely identifies a row in the
Exchange table), then you probably don't want to make
Exchange.area_code_pk as a primary key. Note: it doesn't actually
matter whether it is declared in the database as a primary key.
SQLAlchemy only requires that the primary key uniquely identifies the
row in the database.

Simon

On Thu, Mar 7, 2013 at 2:00 AM, Randall Degges <rdeg...@gmail.com> wrote:
> Hi Mike,
>
> Sorry about that, I actually had a typo there. I've got a correct code
> sample available here
> http://stackoverflow.com/questions/15260842/how-can-i-build-a-foreignkey-to-a-table-which-has-multiple-primary-keys
> (just posted it).
>
> Thank you,
>
> -Randall
>
>
> On Wed, Mar 6, 2013 at 5:54 PM, Michael Bayer <mike...@zzzcomputing.com>
> wrote:
>>
>> a database table can only have one primary key (hence "primary"), but that
>> key can contain more than one column (a "composite" primary key).
>>
>> the model you have here is a little unclear, did you mean for the primary
>> key of Exchange to be "exchange" , and the primary key of PhoneNumber to be
>> the composite of "exchange" and "phone number" ?   that would be my guess as
>> to what you're looking for.
>>
>>
>>
>> On Mar 6, 2013, at 6:05 PM, Randall Degges <rdeg...@gmail.com> wrote:
>>
>> Hi all,
>>
>> I'm having a lot of trouble figuring out how to properly build my
>> ForeignKey column for a table I'm defining. I've outlined my models here:
>> http://pastie.org/6407419# (and put a comment next to the problematic line
>> in my PhoneNumber model).
>>
>> Here's what's happening:
>>
>> My Exchange table has two primary keys. This is required for my use case.
>>
>> The PhoneNumber table I'm trying to define needs a ForeignKey to the
>> Exchange table, but since the Exchange table has two primary keys, I can't
>> figure out how to make the relationship work.
>>
>> Any guidance would be appreciated. Thank you.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to sqlalchemy+unsubscr...@googlegroups.com.
>>
>> To post to this group, send email to sqlalchemy@googlegroups.com.
>> Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to sqlalchemy+unsubscr...@googlegroups.com.
>>
>> To post to this group, send email to sqlalchemy@googlegroups.com.
>> Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
>
>
>
> --
> Randall Degges
> http://rdegges.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to