0

我在 Mnesia 数据库中插入数据时遇到了一些问题。

这是代码:(模式已经存在)

-module(mnesia_test).

-record(messages_queue, {id, ack, order, message}).

-export([start/0, add/0]).

start() ->
    mnesia:start(),
    mnesia:delete_table(messages_queue),
    mnesia:create_table(messages_queue, [{attributes, record_info(fields, messages_queue)}, {type, bag}, {record_name, messages_queue}]).

add() ->
    M = #messages_queue{id = "11223344", ack = [0, 5, 32, 91, 23, 106], order= 0, message="Hello world !"},
    mnesia:write(M).

写入被中止:

Erlang R16B (erts-5.10.1) [source] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V5.10.1  (abort with ^G)
1> mnesia_test:start().
{atomic,ok}
2> mnesia_test:add().
** exception exit: {aborted,no_transaction}
     in function  mnesia:abort/1 (mnesia.erl, line 309)
4

1 回答 1

0

我知道了...

写入必须包含在 mnesia:transaction() 中

于 2013-05-24T13:20:52.497 回答