:mnesia disk_copeis 不适合我的 Elixir

:mnesia disk_copeis not working for my Elixir

> alias :mnesia, as: Mnesia
> Mnesia.create_schema([node()])
> fields = [:id, :to, :from, :body, :format, :metadata]
> Mnesia.create_table(:mail, [attributes: fields, disc_copies: [node()]] )

{:aborted, {:bad_type, :mail, :disc_copies, :nonode@nohost}}

如果我这样做

iex(5)> Mnesia.create_table(:mail, [attributes: fields] )
{:atomic, :ok}

一切正常,但这只是在 RAM 中创建的

如何让 :mnesia 存储在磁盘上。

谢谢

首先尝试命名您的节点:

> iex --name foo

然后您需要确保启动 Mnesia。这对我有用:

alias :mnesia, as: Mnesia
Mnesia.start()
Mnesia.create_schema([node()])
fields = [:id, :to, :from, :body, :format, :metadata]
Mnesia.create_table(:mail, [attributes: fields, disc_copies: [node()]] )

Mnesia 未正确启动。

iex(1)> :mnesia.create_schema([node()])
:ok
iex(2)> fields = [:id, :to, :from, :body, :format, :metadata]
[:id, :to, :from, :body, :format, :metadata]
iex(3)> :mnesia.start
:ok
iex(4)> :mnesia.create_table(:mail, [attributes: fields, disc_copies: [node()]] )
{:atomic, :ok}