Pylons,SQlite和自动增量领域
嘿!
刚刚开始与Pylons一起使用SQLAlchemy,我的模型看起来像这样: from sqlalchemy import Column from sqlalchemy.types import Integer,String from helloworld.model.meta import Base class Person(Base): __tablename__ = "person" id = Column(Integer,primary_key=True) name = Column(String(100)) email = Column(String(100)) def __init__(self,name='',email=''): self.name = name self.email = email def __repr__(self): return "<Person('%s')" % self.name 为了避免sqlite重用可能已被删除的id,我想将AUTOINCREMENT添加到列“id”.我查看了sqlalchemy的文档,看到可以发出sqlite_autoincrement. sqlite_autoincrement似乎是在创建表本身时发出的,我只是想知道在使用模型的声明式样式时如何提供它. 尝试将__table_args__属性包含在传统(非声明性)数据定义样式中传递给Table构造函数的参数中,例如:class Person(Base): __tablename__ = "person" __table_args__ = {'sqlite_autoincrement': True} 如果你必须包含几个参数,请使用此表单(dict必须是最后一个): __table_args__ = ( Unique('foo'),# ... {'sqlite_autoincrement': True} ) 从Declarative SQLAlchemy文档的Table configuration部分:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |