Reputation: 868
-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)?
Upvotes: 2
Views: 651
Reputation: 10254
{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.
Upvotes: 0
Reputation: 146
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).
Upvotes: 3