"bad_type" 尝试创建 mnesia 表时出错
"bad_type" error when trying to create mnesia tables
我这辈子都弄不明白。我正在尝试创建 mnesia 表,但不断收到这个奇怪的错误。
这是我的命令:
ok = mnesia:create_schema(Nodes),
rpc:multicall(Nodes, application, start, [mnesia]),
{_, ok} = mnesia:create_table(rr_events,
[{attributes, record_info(fields, rr_events)},
{index, [#rr_events.key]},
{disc_copies, Nodes}]),
rpc:multicall(Nodes, application, stop, [mnesia]).
这是我的记录:
-record(rr_events, {key, events=[]}).
这是错误:
=PROGRESS REPORT==== 24-Mar-2016::21:53:42 ===
application: mnesia
started_at: nonode@nohost
** exception error: no match of right hand side value
{aborted,{bad_type,rr_events,{index,[2]}}}
in function rr:install/1 (c:/Users/zzzz/Projects/zzz/zzz/rr/rr/_build/default/lib/rr/src/rr.erl, line 13)
知道这可能是什么吗?想不通。
呸!感谢这个 excellent blog post 引导我找到答案,引用:
This error:
{aborted,{bad_type,wrud_record,{index,[2]}}}
will occur if you used the first element of the record to index one
table, like:
-record(wrud_record, {user, date, label, remark, url}).
and
mnesia:create_table( wrud_record,[ {index,[user]}, {attributes,
record_info(fields, wrud_record)}])
, so you should change the index to another element like remark here:
mnesia:create_table( wrud_record,[ {index,[remark]}, {attributes,
record_info(fields, wrud_record)}])
everything will be fine. :)
我最近遇到了这个问题。 Learn you some Erlang 声明如下:
Note that you do not need to put an index on the first field of the record, as this is done for you by default.
如果您只需要在记录的第一个元素上建立索引,那么我建议您省略 {index, [record_name]}
。
此外,虽然 LYSE 的段落暗示它 official Erlang documentation 更进一步并指出:
index. This is a list of attribute names, or integers, which specify the tuple positions on which Mnesia is to build and maintain an extra index table.
我这辈子都弄不明白。我正在尝试创建 mnesia 表,但不断收到这个奇怪的错误。
这是我的命令:
ok = mnesia:create_schema(Nodes),
rpc:multicall(Nodes, application, start, [mnesia]),
{_, ok} = mnesia:create_table(rr_events,
[{attributes, record_info(fields, rr_events)},
{index, [#rr_events.key]},
{disc_copies, Nodes}]),
rpc:multicall(Nodes, application, stop, [mnesia]).
这是我的记录:
-record(rr_events, {key, events=[]}).
这是错误:
=PROGRESS REPORT==== 24-Mar-2016::21:53:42 ===
application: mnesia
started_at: nonode@nohost
** exception error: no match of right hand side value
{aborted,{bad_type,rr_events,{index,[2]}}}
in function rr:install/1 (c:/Users/zzzz/Projects/zzz/zzz/rr/rr/_build/default/lib/rr/src/rr.erl, line 13)
知道这可能是什么吗?想不通。
呸!感谢这个 excellent blog post 引导我找到答案,引用:
This error:
{aborted,{bad_type,wrud_record,{index,[2]}}}
will occur if you used the first element of the record to index one table, like:
-record(wrud_record, {user, date, label, remark, url}).
and
mnesia:create_table( wrud_record,[ {index,[user]}, {attributes, record_info(fields, wrud_record)}])
, so you should change the index to another element like remark here:
mnesia:create_table( wrud_record,[ {index,[remark]}, {attributes, record_info(fields, wrud_record)}])
everything will be fine. :)
我最近遇到了这个问题。 Learn you some Erlang 声明如下:
Note that you do not need to put an index on the first field of the record, as this is done for you by default.
如果您只需要在记录的第一个元素上建立索引,那么我建议您省略 {index, [record_name]}
。
此外,虽然 LYSE 的段落暗示它 official Erlang documentation 更进一步并指出:
index. This is a list of attribute names, or integers, which specify the tuple positions on which Mnesia is to build and maintain an extra index table.