【问题标题】:Peewee primary keys not showing up (Failing row contains null)Peewee 主键未显示(失败行包含 null)
【发布时间】: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


    【解决方案1】:

    问题与 Peewee 没有任何关系,它与转储有关。 Heroku 不会自动为您转储序列,因此我不得不手动重新添加它们。添加这些连接后,连接工作正常。

    【讨论】:

      猜你喜欢
      • 2016-09-09
      • 2022-10-05
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      • 2016-04-07
      • 1970-01-01
      • 2020-06-01
      • 2022-07-29
      相关资源
      最近更新 更多