I have ChicagoBoss application and i want to use mnesia to store data of register user.

I setup {db_adapter, mnesia} in boss.config. Now i try to create mnesia database and table.

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),

But i get crash in both variants of table creating:

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

Thank you.

有帮助吗?

解决方案

The node() parameter on mnesia:create_table should be inside a list:

{atomic, ok} = mnesia:create_table('_ids_', [{attributes, [type, id]}, {disc_copies, [node()]}]);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top