0

I'm trying to save a BossRecord to the database using pgsql adapter, of this way:

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

In ChicagoBoss's shell this returns:

{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.

4

1 回答 1

0

感谢 Evan Miller,我找到了解决方案,就像在这里他说evan miller ChicagoBoss 博客“每个模型的 Id 字段被假定为数据库提供的整数(例如,Postgres 中的 SERIAL 类型)......指定一个新记录的原子 'id' 以外的 id 值将导致错误"

所以我把我的桌子改成:

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

并更改模型(指定表和列的名称):

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

并使用“id”原子来保存记录:

boss_db:save_record(admins:new(id, 1)).
于 2016-04-09T08:24:04.063 回答