Mnesia writes fails

I defined an entry called log . I want to create a mnesia table named log_table . When I try to write a record to a table, I get a 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?

+4
source share
3 answers

By default, it is assumed that the record name matches the table name.

To fix this, you should either name your table simply log , or add the {record_name, log} parameter to your table parameters (as you did in your fix).

It is generally recommended that your record and table be named the same, this makes the code easier to read and debug. You can also use the mnesia:write/1 function only with your record as an argument. Mnesia then finds out which table the record is placed in by looking at the name.

+7
source

I found him. When I changed mnesia:create_table call this

 mnesia:create_table(log_table, [{ram_copies, [node()]}, {record_name, log}, {attributes, record_info(fields, log)}]). 

everything is working fine.

+2
source

What does your definition of journal entries look like? You get the same error if you create a new table from scratch (that is, first delete the Mnesia @ directory).

0
source

Source: https://habr.com/ru/post/1277105/


All Articles