Question

-record(ng, {ng}).

mnesia:create_table(ng, [{type, set}, {attributes, record_info(fields, ng)}]).

I'm getting: {aborted,{bad_type,ng,{attributes,[ng]}}} error.

What's wrong? How to create a mnesia table with one column(which is named)?

Was it helpful?

Solution

The record has to have at least 2 fields. This would work:

-record(ng, {ng, extrafield}).
mnesia:create_table(ng, [{type, set}, {attributes, record_info(fields, ng)}]).

From http://www.erlang.org/doc/man/mnesia.html#create_table-2

"The table must have at least one extra attribute in addition to the key."

Edit: Can't find an answer as to whether a single column is possible, but this 2007 thread indicates not.

I personally do it with key/value columns, like this:

-record(proximaglobal, {key, value}).
mnesia:create_table(proximaglobal, [{attributes, record_info(fields, proximaglobal)}, {disc_only_copies, [node()]}]).
mnesia:sync_transaction(fun() -> mnesia:write(#proximaglobal{key=time, value=WorldTime}) end).
mnesia:sync_transaction(fun() -> mnesia:read(proximaglobal, time) end).

OTHER TIPS

{attributes, AtomList} a list of the attribute names for the records that are supposed to populate the table. The default value is [key, val]. The table must have at least one extra attribute in addition to the key.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top