[問題]sqlalchemy依list創立table column

作者: alfven (馮小丸)   2020-10-23 08:59:30
以下範例來自sqlalchemy官方
https://docs.sqlalchemy.org/en/13/core/metadata.html
## 範例:在資料庫新增一個表
engine = create_engine('sqlite:///:memory:')
meta = MetaData()
employees = Table('employees', meta,
Column('employee_id', Integer, primary_key=True),
Column('employee_name', String(60), nullable=False, key='name'),
Column('employee_dept', Integer, ForeignKey("departments.department_id"))
)
employees.create(engine)
## 範例結束
我想請問 如果有一list
employee_sister = ['sis年紀','sis三圍','sis學校']
我們該如何將employee_sister 傳入employees
再create出一個新的table呢?
作者: sherees (ShaunTheSheep)   2020-10-23 17:56:00
Table(..., *[Column(col, ...) for col in your_list])

Links booklink

Contact Us: admin [ a t ] ucptt.com