python - sqlalchemy.orm.exc.FlushError:实例具有 NULL 身份密钥。(甲骨文数据库)
问题描述
我在将数据插入到烧瓶应用程序的表中时遇到问题。提交到数据库时出现以下错误:
sqlalchemy.orm.exc.FlushError: Instance <TestModel at 0x11120f690> has a NULL identity key. If this is an auto-generated value, check that the database table allows generation of new primary key values, and that the mapped Column object is configured to expect these generated values. Ensure also that this flush() is not occurring at an inappropriate time, such as within a load() event.
我了解 Oracle 使用序列而不是 Autoincrement 并在我的 db.Model 中指定了主键:
class TestModel(db.Model):
__tablename__ = 'TESTTABLE'
id_seq = Sequence('TEST_SEQ')
TESTID = db.Column(db.Integer, id_seq, primary_key=True)
我在 Stackoverflow 上看到了这个确切的错误,它通过降级 cx_Oracle 得到了修复,但我没有这样做。序列已在数据库中创建。我正在运行 python3.7、最新版本的 cx_Oracle 和 Oracle 18.1 DB。
解决方案
推荐阅读
- apache - Apache2 mod_proxy_fcgi ProxyFCGISetEnvIf 目录特定覆盖
- android - try-catch 中 Exception 和 JSONException 的区别
- qt - PyQt 3D for QtQuick (QML) 支持
- assets - Spark Ar headOccluder.obj 加载未发生
- node.js - 在 macOS 终端中找不到 Google Lighthouse 命令
- r - R dplyr - 按名称模式重新排列列
- python - 向记录器添加特定名称
- c++ - 无法在 Windows 中链接 grpc 库
- google-chrome-extension - 与网站链接的 Google Chrome 扩展程序
- python - 为变量动态分配值的最佳方法?