我有两个表计数器和计数
-record(counter, {key, value}).
-record(count, {key, value}).
create() ->
mnesia:create_schema([node()]),
mnesia:start(),
mnesia:create_table(counter, [{attributes, record_info(fields, counter)}, {disc_copies, [node()]}]),
mnesia:create_table(count, [{attributes, record_info(fields, count)}, {disc_copies, [node()]}]),
mnesia:stop().
但是当我尝试运行此功能时
backup()->
mnesia:transaction(fun() ->
Records = mnesia:select(counter, [{'_', [], ['$_']}]),
[ok = mnesia:write(count, Record, write) || Record <- Records]
end).
我有这个错误
2> model:backup().
{aborted,{bad_type,{counter,test,353}}}
当我使用您的代码时:
mnesia:create_table(count, [{record_name, counter}, {attributes, record_info(fields, counter)}, {disc_copies, [node()]}]).
当我尝试运行 model:reset() 时,它会删除表计数和表计数器的数据
我的目标是删除计数器的数据
这是 reset() 的代码
reset() ->
stop(),
destroy(),
create(),
start(),
{ok}.
destroy() ->
mnesia:start(),
mnesia:delete_table(counter),
mnesia:delete_table(person),
mnesia:stop(),
mnesia:delete_schema([node()]).
create() ->
mnesia:create_schema([node()]),
mnesia:start(),
mnesia:create_table(counter, [{attributes, record_info(fields, counter)}, {disc_copies, [node()]}]),
mnesia:create_table(person, [{attributes, record_info(fields, person)}, {disc_copies, [node()]}]),
mnesia:create_table(person_backup,[{disc_copies, [node()]},{attributes, record_info(fields, person)},
{record_name, person}]),
mnesia:stop().