Mnesia写入数据错误?

2009-04-08
Q:我创建了如下一个Mnesia表,为何写入数据时会出现bad type错误呢??
> rd(message, {to, from, content}).
> mnesia:create_table(msg, [{attributes, record_info(fields, message)}]).

> mnesia:dirty_write({message, jojo, oscar, <<"missing you">>}).
** exception exit: {aborted,{no_exists,message}}
in function mnesia:abort/1

> mnesia:dirty_write(msg, {message, jojo, oscar, <<"test">>}).
** exception exit: {aborted,{bad_type,
#message{to = jojo, from = oscar, content = <<"test">>}}}
in function mnesia:abort/1

A:第一次执行dirty_write时提示没有找到message表,当表名和表所存储的record名相同时,写入数据时可以忽略表名,但现在表名并非message而是msg,好吧我们指定一个表名再写入试试,这次却出现了第二个错误提示类型错误,郁闷,原来当表名和record名不同时,创建表的时候应另外添加一个参数{record_name, ...},即:

> mnesia:create_table(msg, [
{attributes, record_info(fields, message)},
{record_name, message}]).

这样就可以正常插入数据了~~

M-OSCAR | Powered by Blogger | Entries (RSS) | Comments (RSS) | Designed by MB Web Design | XML Coded By Cahayabiru.com