python - Peewee 主键未显示(失败行包含 null)
问题描述
我正在使用 peewee ORM 来管理一些 Postgres 数据库。我最近遇到了一个问题,即主键不会在应有的调用时save()
或被execute()
调用时自动添加。
这是被调用的代码:
Macro.insert(name=name, display_text=text).on_conflict(conflict_target=(Macro.name,), preserve=(Macro.display_text,), update={Macro.name: name}).execute()
这是错误:
Command raised an exception: IntegrityError: null value in column "id" violates non-null constraint;
DETAIL: Failing row contains (null, nametexthere, displaytexthere)
宏类有一个id (AutoField [set to be primary key]), name (CharField), and display_text (CharField)
. 我已经尝试使用内置的 PrimaryKeyField 和一个 IntegerField 设置为主键以保持不变。
之前,我使用 Heroku 没有问题。从那以后,我将我的应用程序迁移到了我的 Raspberry Pi,这就是这个问题出现的时候。
这也不是我遇到此问题的唯一情况。我有另一个具有相同 AutoField 主键的数据库,从 Heroku 到 Pi 的转换似乎已经中断。那一个使用save()
方法而不是insert()/execute()
,但仍然出现失败的行错误。
还应该提到其他非插入查询工作正常。我仍然可以毫无问题地选择。
解决方案
这个问题与 Peewee 没有任何关系,它与转储有关。Heroku 不会自动为您转储序列,因此我不得不手动重新添加它们。添加这些连接后,连接工作正常。
推荐阅读
- excel - 根据其他单元格值更改单元格范围参考
- linux - Linux 内核在引导时无法从 SD 卡中检测到 rootfs
- go - 在 Go 中 defer 关键字是如何工作的
- sql-server - 如何防止使用 OUTPUT 的 SQL Server 合并更新目标表
- angular - 将参数传递给 Angular 路由器中的匹配器时出现 AOT 错误
- image - 裁剪缩略图并在没有覆盖提示的情况下替换
- excel - 按降序遍历范围
- ios - 如何使我的应用程序显示为从 SD 卡/相机导入照片的选项
- android - 创建 Android 图标的“添加图像资源”在哪里?
- excel - 未收到 Next 的错误消息