挂架、SQlite和自动递增字段
嘿! 刚刚开始与SQLAlchemy一起使用挂架,我的模型如下所示:挂架、SQlite和自动递增字段,sqlite,sqlalchemy,pylons,auto-increment,Sqlite,Sqlalchemy,Pylons,Auto Increment,嘿! 刚刚开始与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) na
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
来自sqlalchemy导入列的
从sqlalchemy.types导入整数、字符串
来自helloworld.model.meta导入库
班级人员(基本):
__tablename_u=“person”
id=列(整数,主键=True)
名称=列(字符串(100))
电子邮件=列(字符串(100))
定义初始化(self,姓名='',电子邮件=''):
self.name=名称
self.email=电子邮件
定义报告(自我):
return“尝试使用传统(非声明性)数据定义样式传递给表
构造函数的参数包含表
属性,例如:
class Person(Base):
__tablename__ = "person"
__table_args__ = {'sqlite_autoincrement': True}
如果必须包含多个参数,请使用此表单(dict必须是最后一个):
从声明性SQLAlchemy文档的部分:
除了名称、元数据和映射的列
参数以外的表参数是使用\uuuu Table\u args\uuuu
类属性指定的。此属性包含通常发送到表
构造函数的位置参数和关键字参数
__table_args__ = (
Unique('foo'),
# ...
{'sqlite_autoincrement': True}
)