简体   繁体   中英

with python sqlalchemy, how do define multiple-column primary key

I am following the tutorial at https://docs.sqlalchemy.org/en/latest/core/tutorial.html

I see an example for primary key, it seems to use just one column

>>> users = Table('users', metadata,
...     Column('id', Integer, primary_key=True),
...     Column('name', String),
...     Column('fullname', String),
... )

how do define primary key with a sequence of columns?

try like this:

    >>> users = Table('users', metadata,
...     Column('id', Integer, primary_key=True),
...     Column('name', String, primary_key=True),
...     Column('fullname', String),
... )

use primary_key=True on any column to primary as key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM