【发布时间】:2019-01-01 23:49:16
【问题描述】:
我正在使用 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(),但仍然显示失败的行错误。
还应该提到其他非插入查询工作正常。我仍然可以毫无问题地选择。
【问题讨论】:
标签: python postgresql peewee