Pylons, SQlite and autoincrementing fields

后端 未结 1 660
既然无缘
既然无缘 2021-01-02 16:09

Hey! Just started working with Pylons in conjunction with SQLAlchemy, and my model looks something like this:

from sqlalchemy import Column
from sqlalchemy.t         


        
相关标签:
1条回答
  • 2021-01-02 16:30

    Try including a __table_args__ attribute with the arguments you would pass to Table constructors in the traditional (non-declarative) data definition style, e.g.:

    class Person(Base):
        __tablename__ = "person"
        __table_args__ = {'sqlite_autoincrement': True}
    

    If you have to include several arguments, use this form instead (dict has to be last):

    __table_args__ = (
        Unique('foo'),
        # ...
        {'sqlite_autoincrement': True}
    )
    

    From the Table configuration section of the Declarative SQLAlchemy documentation:

    Table arguments other than the name, metadata, and mapped Column arguments are specified using the __table_args__ class attribute. This attribute accommodates both positional as well as keyword arguments that are normally sent to the Table constructor.

    0 讨论(0)
提交回复
热议问题