<div dir="ltr">Hi,<div><br></div><div>Make sure to:</div><div><br>1. Start your erlang node with <font face="monospace">-mnesia dir "/path/to/where/you/want/to/put/mnesia"</font></div><div>2. Create the schema first</div><div>3. start mnesia by using command <font face="monospace">mnesia:start()</font></div><div>4. The create your tables</div><div><br></div><div>>> I have a db_init function that initializes db so that if tables do not exist they are created (ram with disc_copies)</div><div>If you want to do a table existence detection, you can do like the following:<br><br></div><div><font face="monospace">case catch mnesia:table(your_table_name, version) of</font></div><div><font face="monospace">  {{_, _}, []} </font></div><div><font face="monospace">    -> table_exists;<br><br></font></div><div><font face="monospace">  Fail when Fail =:= {'EXIT',{aborted,{no_exists,your_table_name,version}}}; Fail =:= {aborted,{no_exists,your_table_name,version}} </font></div><div><font face="monospace">    -> %% create your your_table_name table</font></div><div><font face="monospace">end</font></div><div><br></div><div>Also, as i stated above, you have to create your schema first then start mnesia application. Example:</div><div><br></div><div><font face="monospace">case mnesia:create_schema([node()]) of</font></div><div><font face="monospace">  {error,{_,{already_exists,_}}} -></font></div><font face="monospace">      io:format("Schema Already exists~n");</font><div><font face="monospace"><br>    ok -><br>      io:format("Schema Created~n")</font></div><div><font face="monospace">end,</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">application:ensure_started(mnesia),</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">%% then init your tables here</font></div><div><font face="monospace">%%</font></div><div><font face="monospace">%%</font></div><div><font face="monospace">.</font></div><div><br></div><div>Please read <a href="http://erlang.org/doc/apps/mnesia/Mnesia_chap2.html">http://erlang.org/doc/apps/mnesia/Mnesia_chap2.html</a></div><div><br></div><div>>> However half of the time it destroys old table returning {atomic, ok} and another half it returns with already_exists</div><div>I'm not sure with this. But maybe i think your schema location was not consistent</div><div><br></div><div>I suggest you to use rebar3 to manage your project. </div><div><br></div><div><br></div><div><br><br><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Pada tanggal Jum, 8 Nov 2019 pukul 07.57 Karlo Kuna <<a href="mailto:kuna.prime@gmail.com">kuna.prime@gmail.com</a>> menulis:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi, <br><div><br></div><div>I have problem with mnesia initialization, </div><div><br></div><div>I have a db_init function that initializes db so that if tables do not exist they are created (ram with disc_copies). For example:</div><div><br></div><div>db_init() -><br>    mnesia:create_table(some_record,[{attributes, record_info(fields, some_record)},<br>                                                                {type, bag}, {disc_copies, [node()]}]).<br><br></div><div>I'm running this function on the app start to make sure the table exists and is ready. </div><div>However half of the time it destroys old table returning {atomic, ok} and another half it returns with already_exists. Also, this happens in the regular fashion, if I have n starts of application, even starts would destroy data and even wold keeps old data. I know that I am missing something probably obvious here but if anyone has any insights on why is this happening and how to fix it I would greatly appreciate it.</div><div><br></div><div>Thank You, </div><div>Karlo. </div></div>
</blockquote></div>