前端之家收集整理的这篇文章主要介绍了
【SQLAlchemy】PostgreSQL的自增长主键定义,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#coding=utf-8
#!/usr/bin/envpython
fromsqlalchemyimportcreate_engine
engine=create_engine('postgresql://ms:ms@localhost:5432/stockpy')
fromsqlalchemy.ext.declarativeimportdeclarative_base
Base=declarative_base()
fromsqlalchemyimportTable,Column,String,Integer,Sequence
classTest1(Base):
__tablename__='test1'
id=Column(Integer,Sequence('test1_id_seq'),primary_key=True)
name=Column(String(50))
ed_t1=Test1(name='fuckpython')
fromsqlalchemy.ormimportsessionmaker
Session=sessionmaker(bind=engine)
session=Session()
session.add(ed_t1)
session.commit()
原文链接:https://www.f2er.com/postgresql/195007.html