ChicagoBoss和mnesia创建表错误

时间:2013-06-11 12:42:00

标签: erlang chicagoboss

我有ChicagoBoss个应用程序,我想使用mnesia来存储注册用户的数据。

我在{db_adapter, mnesia}设置了boss.config。现在我尝试创建mnesia数据库和表。

mnesia:stop(),
mnesia:create_schema([node()]),
mnesia:change_table_copy_type(schema, node(), disc_copies),
ok = mnesia:start(),
ExistingTables = mnesia:system_info(tables),
TablesToCreate = (?MODELS ++ ['_ids_']) -- ExistingTables,

lists:foreach(fun(T) ->
                    case T of
                        '_ids_' ->
                            {atomic, ok} = mnesia:create_table('_ids_', [{attributes, [type, id]}, {disc_copies, node()}]);
                        _ ->
                            % get model record
                            ModelRecord = boss_record_lib:dummy_record(lists:nth(1, ?MODELS)),
                            % get model attributes
                            Attributes = ModelRecord:attribute_names(),
                            % setup mnesia tables
                            {atomic, ok} = mnesia:create_table(lists:nth(1, ?MODELS), [{attributes, Attributes}, {disc_copies, Node}])
                    end
                  end,
                  TablesToCreate),

但我在表创建的两个变体中都崩溃了:

{aborted,{bad_type,my_model, {disc_copies,nonode@nohost}}}

谢谢。

1 个答案:

答案 0 :(得分:2)

node()上的mnesia:create_table参数应位于列表中:

{atomic, ok} = mnesia:create_table('_ids_', [{attributes, [type, id]}, {disc_copies, [node()]}]);