Peewee 主键未显示(失败行包含空值)
Peewee primary keys not showing up (Failing row contains 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)
宏 class 有一个 id (AutoField [set to be primary key]), name (CharField), and display_text (CharField)
。我已经尝试使用内置的 PrimaryKeyField 和一个 IntegerField 设置为主键没有变化。
以前,我使用 Heroku 没有问题。我已经将我的应用程序迁移到我的 Raspberry Pi,这就是这个问题突然出现的时候。
这也不是我遇到此问题的唯一情况。我有另一个具有相同 AutoField 主键的数据库,它似乎在从 Heroku 到 Pi 的过渡中损坏了。那个使用 save()
方法而不是 insert()/execute()
,但失败的行错误仍然出现。
还应该提到其他非插入查询工作正常。我仍然 select 没有问题。
问题与 Peewee 无关,与转储有关。 Heroku 不会自动为您转储序列,因此我不得不再次手动添加它们。添加这些后,连接工作正常。
我正在使用 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)
宏 class 有一个 id (AutoField [set to be primary key]), name (CharField), and display_text (CharField)
。我已经尝试使用内置的 PrimaryKeyField 和一个 IntegerField 设置为主键没有变化。
以前,我使用 Heroku 没有问题。我已经将我的应用程序迁移到我的 Raspberry Pi,这就是这个问题突然出现的时候。
这也不是我遇到此问题的唯一情况。我有另一个具有相同 AutoField 主键的数据库,它似乎在从 Heroku 到 Pi 的过渡中损坏了。那个使用 save()
方法而不是 insert()/execute()
,但失败的行错误仍然出现。
还应该提到其他非插入查询工作正常。我仍然 select 没有问题。
问题与 Peewee 无关,与转储有关。 Heroku 不会自动为您转储序列,因此我不得不再次手动添加它们。添加这些后,连接工作正常。