简体   繁体   English

boss_db:save_record不适用于PostgreSQL适配器

[英]boss_db:save_record not working with PostgreSQL adapter

I'm trying to save a BossRecord to the database using pgsql adapter, of this way: 我正在尝试使用pgsql适配器将BossRecord保存到数据库,这种方式是:

boss_db:save_record(admins:new("admins-1", 1)). 

In ChicagoBoss's shell this returns: 在ChicagoBoss的外壳中,将返回:

{ok,{admins,"admins-1",1}}

But the record is not actually being saved in the database. 但是记录实际上并没有保存在数据库中。

This is my table: 这是我的桌子:

CREATE TABLE admins("
        "ID integer primary key,"
        "user_ID integer"
    ")

My model: 我的模特:

-module(admins, [Id, UserId]).
-compile(export_all).

Thanks. 谢谢。

Thanks to Evan Miller I've found the solution, like here he says evan miller ChicagoBoss blog "the Id field of each model is assumed to be an integer supplied by the database (eg, a SERIAL type in Postgres)... specifying an Id value other than the atom 'id' for a new record will result in an error" 多亏了Evan Miller,我找到了解决方案,就像他在这里说的那样, Evan Miller ChicagoBoss博客 “假定每个模型的ID字段都是数据库提供的整数(例如Postgres中的SERIAL类型)...指定一个新记录的原子“ id”以外的id值将导致错误“

So I changed my table to: 所以我将表更改为:

        "CREATE TABLE IF NOT EXISTS admins("
            "ID serial primary key,"
            "user_ID integer"
        ")"

And also change the model (to specify the name of the table and the columns): 并更改模型(以指定表和列的名称):

-module(admin, [Id, UserId]).
-columns([{id, "ID"}, {user_id, "user_ID"}]).
-table("admins").

And using 'id' atom to save the record: 并使用'id'原子保存记录:

boss_db:save_record(admins:new(id, 1)).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM