Reputation: 23
So I'm getting {aborted,{bad_type,link,disc_copies, '[email protected]'}}
(it is returned by my init_db/0
function):
-record(link, {hash, original, timestamp}).
init_db() ->
application:set_env(mnesia, dir, "/tmp/mnesia_db"),
mnesia:create_schema([node()]),
mnesia:start(),
mnesia:create_table( link,[
{index,[timestamp]},
{attributes, record_info(fields, link)},
{disc_copies, [node()]}]).
Without {disc_copies, [node()]}
table is properly created.
Upvotes: 2
Views: 1229
Reputation: 37
I faced the same issue.
I received the {aborted {bad_type,account,disc_copies,nonode@nohost}}
because I was calling the mnesia:wait_for_tables
before the schema creation. Changing the order solved this for me.
Upvotes: 1
Reputation: 563
You may need to change the schema
table to disc_copies
which seems to affect the entire node.
mnesia:change_table_copy_type(schema, node(), disc_copies)
From the mnesia docs:
This function can also be used to change the storage type of the table named schema. The schema table can only have ram_copies or disc_copies as the storage type. If the storage type of the schema is ram_copies, no other table can be disc-resident on that node.
After this, you should be able to create disc_copies
tables on the node.
Upvotes: 2
Reputation: 20004
Verify write permissions on the parent directory of the mnesia dir you're specifying via application:set_env/3
. If the mnesia dir parent directory doesn't allow you to write, you'll get this error. (Another way to get this error is to forget to set mnesia dir entirely, but your set_env
call is clearly doing that.)
Update: looking more carefully at your reported error, I see the node mentioned in the error is not in a list:
{aborted,{bad_type,link,disc_copies, '[email protected]'}}
This might mean that the code you show in your question doesn't match what's really running. Specifically, if you call mnesia:create_table/2
passing a node instead of a list of nodes in the disc_copies
tuple, as shown below, you'll get the same exact error:
mnesia:create_table(link,[{index,[timestamp]},
{attributes, record_info(fields, link)},
{disc_copies, node()}]). % note no list here, should be [node()]
Upvotes: 3