Manan Bordia
Manan Bordia

Reputation: 492

Foreign Key with argument None : Sqlalchemy

So, I was going through a code base and found this :

user_id_column = Column('user_id', None, ForeignKey('people.people_id'))

I can clearly understand that this is a foreign key column and referencing people_id column from people schema.

Just wanted to know what is the purpose of None ? The type of data in people_id column is Integer.

Upvotes: 0

Views: 133

Answers (1)

Henry
Henry

Reputation: 3944

The second argument is the type. From the docs:

If the type is None or is omitted, it will first default to the special type NullType. If and when this Column is made to refer to another column using ForeignKey and/or ForeignKeyConstraint, the type of the remote-referenced column will be copied to this column as well, at the moment that the foreign key is resolved against that remote Column object.

So setting the type to None means it uses the type of the foreign key.

Upvotes: 1

Related Questions