BIGINT 自动增量是否适用于带有 sqlite 的 SQLAlchemy? [英] Does BIGINT auto increment work for SQLAlchemy with sqlite?

查看:32
本文介绍了BIGINT 自动增量是否适用于带有 sqlite 的 SQLAlchemy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 SQLAlchemy 声明一个表.我想在表中包含一个 BIGINT 自动递增主键.这似乎不适用于 SQLite 作为数据库后端.另一方面,使用 INTEGER 自动递增主键效果很好.

I am trying to declare a table using SQLAlchemy. I'd like to include a BIGINT auto incrementing primary key in the table. This does not seem to work with sqlite as the DB backend. On the other hand, having INTEGER auto incrementing primary key works just fine.

我读到 sqlite 有 ROWID,它是一个有符号的 bigint.但是有没有办法拥有一个 BIGINT 自动增量字段?这样我就可以交换后端而不必担心特定于数据库的问题(假设 MySQL 和 Postgres 支持 bigint 自动递增字段).

I read that sqlite has ROWID that is a signed bigint. But is there a way to have a BIGINT auto increment field? This way I can swap backends without worrying about db specific issues (assuming MySQL and Postgres support bigint auto incrementing fields).

谢谢.

推荐答案

Sqlite 不允许将 BIGINT 用作具有自动增量的主键.

Sqlite doesn't allow BIGINT used as an primary key with autoincrement.

但是,由于 sqlite 列类型的动态特性,您可以创建后端特定的列类型并使用 INTEGER 类型在 sqlite 后端的情况下,请参阅 SQLAlchemy:如何根据其后端有条件地选择列的类型.

But, due to dynamic nature of sqlite column types, you can make a backend-specific column type and use INTEGER type in case of sqlite backend, see SQLAlchemy: How to conditionally choose type for column by depending on its backend.

希望有所帮助.

这篇关于BIGINT 自动增量是否适用于带有 sqlite 的 SQLAlchemy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆