SQLAlchemy 中的 BIGINT 和 BigInteger 有什么区别?

Lib*_*aco 3 python sqlalchemy

大整数

class BigInteger(Integer):

    """A type for bigger ``int`` integers.

    Typically generates a ``BIGINT`` in DDL, and otherwise acts like
    a normal :class:`.Integer` on the Python side.

    """

    __visit_name__ = 'big_integer'
Run Code Online (Sandbox Code Playgroud)

大数据

class BIGINT(BigInteger):

    """The SQL BIGINT type."""

    __visit_name__ = 'BIGINT'
Run Code Online (Sandbox Code Playgroud)

但是 Column(BigInteger) 和 Column(BIGINT) 都可以工作,都可以在 postgresql 中定义一个 bigint。如何区分它们?

blu*_*ote 6

它们都可以工作,但是BIGINT必须从特定的方言导入,例如您的情况下的 postgres。如果您将数据库更改为例如。mysql,你可能有问题。使用BigIntegersqlalchemy 处理映射,取决于您使用的数据库,所以您应该更喜欢这个。