SQLite does not support autoincrement for composite primary keys. with_variant

x·2024년 3월 5일
0

pytest

목록 보기
5/6
url = "sqlite:///:memory:"
engine = create_engine(
    url,
)

ssession = scoped_session(
    sessionmaker(autocommit=False, autoflush=False, bind=engine),
    scopefunc=_app_ctx_stack.__ident_func__,
)

Base = declarative_base()

# conftest에서 pytest를 위한 스키마 생성. 특정 테이블만 생성하도록 함
Base.metadata.create_all(
        bind=engine, tables=[table.__table__ for table in TO_BE_CREATED_TABLES]
    )

SQLite does not support autoincrement for composite primary keys

table = Table(
    "my_table", metadata,
    Column("id", BigInteger().with_variant(Integer, "sqlite"), primary_key=True)
)

autoincrement 사용 할 수 없을 때 test 환경이면 autoincrement False 할당

Column(
        ...
        autoincrement=True if os.getenv("ENV") != "test" else False
    )

0개의 댓글