automatic datatype for a ForeignKey

0 views
Skip to first unread message

Alexandre CONRAD

unread,
Oct 17, 2006, 9:34:40 AM10/17/06
to sqlalchemy
Hello,

I was wondering why not having an automatic datatype assigned to a FK
column instead of repeating twice the data type that has to be set...

a user table would have:

Column('user_id', Integer, primary_key=True),

and an address table refereing to a user would have:

Column('user_id', ForeignKey("users.user_id")),

Here, I don't specify that the FK column is an Integer, because some
clever mechanics would do that for me.

I suppose that this was already thougt before, but I was just wondering...

Regards,
--
Alexandre CONRAD

Michael Bayer

unread,
Oct 17, 2006, 1:33:06 PM10/17/06
to sqlalchemy
i like this idea, and i committed a check in the foreign key init to
set the type if a column has NULLTYPE for a type (which is the default
if you send None). but having the parameter optional requires some
positional *args games which id rather not get into right now, so it
looks like:

Column('user_id', None, ForeignKey("users.user_id"))

Reply all
Reply to author
Forward
0 new messages