I defined a record named log
. I want to create an mnesia table with name log_table
. When I try to write a record to table, I get bad_type
error as follows:
(node1@kitt)4> mnesia:create_table(log_table, [{ram_copies, [node()]},
{attributes, record_info(fields, log)}]).
{atomic,ok}
(node1@kitt)5> mnesia:dirty_write(log_table, #log{id="hebelek"}).
** exception exit: {aborted,{bad_type,#log{id = "hebelek"}}}
in function mnesia:abort/1
What am I missing?
By default the record name is assumed to be the same as the table name.
To fix this you should either name your table just log
or append the option {record_name, log}
in your table options (as you've done in your fix).
It is usually good practice to let your record and table be named the same thing, it makes the code easier to read and debug. You can also then use the mnesia:write/1
function with just your record as only argument. Mnesia then figures out which table to put the record in by looking at the name.
I've found it. When I changed mnesia:create_table
call to this
mnesia:create_table(log_table, [{ram_copies, [node()]},
{record_name, log},
{attributes, record_info(fields, log)}]).
everything works OK.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With