On Jul 1, 2011, at 4:12 PM, Kartik Lakhotia wrote:

> Hi all,
> I am new to sqlalchemy and i have a very basic doubt
> If i specify multiple columns as foreign key using the foreign key 
> constraint, is it necessary that atleast one of the referenced columns must 
> be unique.
> I tried by specifying the unique constraint on the referenced columns making 
> the combination of those columns unique but it doesnt work.

This is a limitation of relational databases.   Foreign keys are intended to 
reference the primary key of a table in most cases, and as an occasional 
fallback a column that has a UNIQUE constraint can be referenced, but this is 
not a common practice.

>From http://en.wikipedia.org/wiki/Foreign_key

"The foreign key identifies a column or set of columns in one (referencing) 
table that refers to a column or set of columns in another (referenced) table. 
The columns in the referencing table must reference the columns of the primary 
key or other superkey in the referenced table."

Note that if your table has a composite (multicolumn) primary key, the foreign 
key from another table must be created as a "composite" ForeignKeyConstraint(), 
as in the example at 
http://www.sqlalchemy.org/docs/core/schema.html#metadata-constraints .




-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to