error when migrate from mnesia to mysql backend

Hi,
FreeBSD 10.3
Ejabberd 17.8

ejabberd.yml

auth_method: sql
ql_type: mysql
sql_server: "localhost"
sql_database: "ejabberd"
sql_username: "ejabberd"
sql_password: "111111"
## If you want to specify the port:
sql_port: 3306
default_db: sql

#ejabberdctl live
(ejabberd@rtr)1> ejd2sql:export(<<"rtr.host.ru">>, sql).
21:41:37.617 [error] Failed export for module mod_irc and table irc_custom: {no_exists,irc_custom}
21:42:14.353 [error] Failed export for module mod_pubsub and table pubsub_item: function_clause
21:42:14.359 [error] SQL transaction restarts exceeded
** Restarts: 10
** Last abort reason: "#HY000Incorrect integer value: 'unknown' for column 'nodeid' at row 1"
** Stacktrace: [{ejabberd_sql,sql_query_t,1,[{file,"src/ejabberd_sql.erl"},{line,180}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejabberd_sql,outer_transaction,3,[{file,"src/ejabberd_sql.erl"},{line,490}]},{ejabberd_sql,run_sql_cmd,4,[{file,"src/ejabberd_sql.erl"},{line,427}]},{p1_fsm,handle_msg,10,[{file,"src/p1_fsm.erl"},{line,582}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
** When State == {state,<0.413.0>,mysql,undefined,30000,<<"rtr.host.ru">>,{{[],[]},0,1000}}
21:42:14.359 [error] Failed export for module mod_pubsub and table pubsub_state: {{badmatch,{aborted,"#HY000Incorrect integer value: 'unknown' for column 'nodeid' at row 1"}},[{ejd2sql,output,4,[{file,"src/ejd2sql.erl"},{line,175}]},{mnesia_tm,apply_fun,3,[{file,"mnesia_tm.erl"},{line,836}]},{mnesia_tm,execute_transaction,5,[{file,"mnesia_tm.erl"},{line,811}]},{ejd2sql,'-export/3-fun-2-',4,[{file,"src/ejd2sql.erl"},{line,81}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejd2sql,export,3,[{file,"src/ejd2sql.erl"},{line,79}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejd2sql,export,2,[{file,"src/ejd2sql.erl"},{line,70}]}]}
21:42:14.359 [error] Failed export for module mod_pubsub and table pubsub_node: function_clause
21:42:14.572 [error] SQL transaction restarts exceeded
** Restarts: 10
** Last abort reason: "#23000Duplicate entry 'elena.m-ba@rtr.host.ru-brn' for key 'i_sr_user_jid_group'"
** Stacktrace: [{ejabberd_sql,sql_query_t,1,[{file,"src/ejabberd_sql.erl"},{line,180}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejabberd_sql,outer_transaction,3,[{file,"src/ejabberd_sql.erl"},{line,490}]},{ejabberd_sql,run_sql_cmd,4,[{file,"src/ejabberd_sql.erl"},{line,427}]},{p1_fsm,handle_msg,10,[{file,"src/p1_fsm.erl"},{line,582}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
** When State == {state,<0.415.0>,mysql,undefined,30000,<<"rtr.host.ru">>,{{[],[]},0,1000}}
21:42:14.577 [error] Failed export for module mod_shared_roster and table sr_user: {badmatch,{aborted,"#23000Duplicate entry 'elena.m-ba@rtr.host.ru-brn' for key 'i_sr_user_jid_group'"}}
ok
(ejabberd@rtr)2>

If I delete this entry elena.m-ba@rtr.host.ru-brn from shared_roster, then migrate stop in another jid in shared_roster.
Thanks.

I updated to version ejabberd

I updated to version ejabberd 17.12.
Also was updated the MySql scheme
But the issue still remain.

Please tell me why there is an error during the migration?

14:38:53.572 [warning] Ignoring export for module mod_irc: Mnesia table irc_custom doesn't exist (most likely because the module is unused)
14:39:35.036 [error] Failed export for module pubsub_db and table pubsub_node: function_clause
14:39:35.156 [error] SQL transaction restarts exceeded
** Restarts: 10
** Last abort reason: "#23000Cannot add or update a child row: a foreign key constraint fails (`ejabberd`.`pubsub_state`, CONSTRAINT `pubsub_state_ibfk_1` FOREIGN KEY (`nodeid`) REFERENCES `pubsub_node` (`nodeid`) ON DELETE CASCADE)"
** Stacktrace: [{ejabberd_sql,sql_query_t,1,[{file,"src/ejabberd_sql.erl"},{line,186}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejabberd_sql,outer_transaction,3,[{file,"src/ejabberd_sql.erl"},{line,497}]},{ejabberd_sql,run_sql_cmd,4,[{file,"src/ejabberd_sql.erl"},{line,434}]},{p1_fsm,handle_msg,10,[{file,"src/p1_fsm.erl"},{line,582}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
** When State == {state,<0.449.0>,mysql,undefined,30000,<<"rtr.host.ru">>,{{[],[]},0,1000}}
14:39:35.161 [error] Failed export for module pubsub_db and table pubsub_state: {{badmatch,{aborted,"#23000Cannot add or update a child row: a foreign key constraint fails (`ejabberd`.`pubsub_state`, CONSTRAINT `pubsub_state_ibfk_1` FOREIGN KEY (`nodeid`) REFERENCES `pubsub_node` (`nodeid`) ON DELETE CASCADE)"}},[{ejd2sql,output,4,[{file,"src/ejd2sql.erl"},{line,186}]},{mnesia_tm,apply_fun,3,[{file,"mnesia_tm.erl"},{line,836}]},{mnesia_tm,execute_transaction,5,[{file,"mnesia_tm.erl"},{line,811}]},{ejd2sql,'-export/3-fun-4-',5,[{file,"src/ejd2sql.erl"},{line,87}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejd2sql,export,3,[{file,"src/ejd2sql.erl"},{line,85}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejd2sql,export,2,[{file,"src/ejd2sql.erl"},{line,71}]}]}
14:39:35.166 [error] Failed export for module pubsub_db and table pubsub_item: badarg
14:39:35.166 [warning] Ignoring export for module mod_push: Mnesia table push_session doesn't exist (most likely because the module is unused)

(ejabberd@rtr)3> ejd2sql:export(<<"rtr.host.ru">>, sql).
14:40:31.953 [warning] Ignoring export for module mod_irc: Mnesia table irc_custom doesn't exist (most likely because the module is unused)
14:41:07.900 [error] SQL transaction restarts exceeded
** Restarts: 10
** Last abort reason: [35,50,51,48,48,48,68,117,112,108,105,99,97,116,101,32,101,110,116,114,121,32,39,209,135,208,176,209,130,95,209,128,208,180,209,129,45,114,116,114,46,110,101,119,115,116,97,114,46,114,117,39,32,102,111,114,32,107,101,121,32,39,105,95,109,117,99,95,114,111,111,109,95,110,97,109,101,95,104,111,115,116,39]
** Stacktrace: [{ejabberd_sql,sql_query_t,1,[{file,"src/ejabberd_sql.erl"},{line,186}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejabberd_sql,outer_transaction,3,[{file,"src/ejabberd_sql.erl"},{line,497}]},{ejabberd_sql,run_sql_cmd,4,[{file,"src/ejabberd_sql.erl"},{line,434}]},{p1_fsm,handle_msg,10,[{file,"src/p1_fsm.erl"},{line,582}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
** When State == {state,<0.446.0>,mysql,undefined,30000,<<"rtr.host.ru">>,{{[],[]},0,1000}}
14:41:07.908 [error] Failed export for module mod_muc and table muc_room: {{badmatch,{aborted,[35,50,51,48,48,48,68,117,112,108,105,99,97,116,101,32,101,110,116,114,121,32,39,209,135,208,176,209,130,95,209,128,208,180,209,129,45,114,116,114,46,110,101,119,115,116,97,114,46,114,117,39,32,102,111,114,32,107,101,121,32,39,105,95,109,117,99,95,114,111,111,109,95,110,97,109,101,95,104,111,115,116,39]}},[{ejd2sql,output,4,[{file,"src/ejd2sql.erl"},{line,186}]},{mnesia_tm,apply_fun,3,[{file,"mnesia_tm.erl"},{line,836}]},{mnesia_tm,execute_transaction,5,[{file,"mnesia_tm.erl"},{line,811}]},{ejd2sql,'-export/3-fun-4-',5,[{file,"src/ejd2sql.erl"},{line,87}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejd2sql,export,3,[{file,"src/ejd2sql.erl"},{line,85}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejd2sql,export,2,[{file,"src/ejd2sql.erl"},{line,71}]}]}
14:41:07.954 [error] SQL transaction restarts exceeded
** Restarts: 10
** Last abort reason: "#23000Duplicate entry 'virt@rtr.host.ru-rtr.host.ru' for key 'i_muc_registered_jid_host'"
** Stacktrace: [{ejabberd_sql,sql_query_t,1,[{file,"src/ejabberd_sql.erl"},{line,186}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejabberd_sql,outer_transaction,3,[{file,"src/ejabberd_sql.erl"},{line,497}]},{ejabberd_sql,run_sql_cmd,4,[{file,"src/ejabberd_sql.erl"},{line,434}]},{p1_fsm,handle_msg,10,[{file,"src/p1_fsm.erl"},{line,582}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
** When State == {state,<0.447.0>,mysql,undefined,30000,<<"rtr.host.ru">>,{{[],[]},0,1000}}
14:41:07.961 [error] Failed export for module mod_muc and table muc_registered: {{badmatch,{aborted,"#23000Duplicate entry 'virt@rtr.host.ru-rtr.host.ru' for key 'i_muc_registered_jid_host'"}},[{ejd2sql,output,4,[{file,"src/ejd2sql.erl"},{line,186}]},{mnesia_tm,apply_fun,3,[{file,"mnesia_tm.erl"},{line,836}]},{mnesia_tm,execute_transaction,5,[{file,"mnesia_tm.erl"},{line,811}]},{ejd2sql,'-export/3-fun-4-',5,[{file,"src/ejd2sql.erl"},{line,87}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejd2sql,export,3,[{file,"src/ejd2sql.erl"},{line,85}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejd2sql,export,2,[{file,"src/ejd2sql.erl"},{line,71}]}]}
14:41:09.671 [error] Failed export for module pubsub_db and table pubsub_node: function_clause
14:41:09.766 [error] SQL transaction restarts exceeded
** Restarts: 10
** Last abort reason: "#23000Cannot add or update a child row: a foreign key constraint fails (`ejabberd`.`pubsub_state`, CONSTRAINT `pubsub_state_ibfk_1` FOREIGN KEY (`nodeid`) REFERENCES `pubsub_node` (`nodeid`) ON DELETE CASCADE)"
** Stacktrace: [{ejabberd_sql,sql_query_t,1,[{file,"src/ejabberd_sql.erl"},{line,186}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejabberd_sql,outer_transaction,3,[{file,"src/ejabberd_sql.erl"},{line,497}]},{ejabberd_sql,run_sql_cmd,4,[{file,"src/ejabberd_sql.erl"},{line,434}]},{p1_fsm,handle_msg,10,[{file,"src/p1_fsm.erl"},{line,582}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
** When State == {state,<0.449.0>,mysql,undefined,30000,<<"rtr.host.ru">>,{{[],[]},0,1000}}
14:41:09.768 [error] Failed export for module pubsub_db and table pubsub_state: {{badmatch,{aborted,"#23000Cannot add or update a child row: a foreign key constraint fails (`ejabberd`.`pubsub_state`, CONSTRAINT `pubsub_state_ibfk_1` FOREIGN KEY (`nodeid`) REFERENCES `pubsub_node` (`nodeid`) ON DELETE CASCADE)"}},[{ejd2sql,output,4,[{file,"src/ejd2sql.erl"},{line,186}]},{mnesia_tm,apply_fun,3,[{file,"mnesia_tm.erl"},{line,836}]},{mnesia_tm,execute_transaction,5,[{file,"mnesia_tm.erl"},{line,811}]},{ejd2sql,'-export/3-fun-4-',5,[{file,"src/ejd2sql.erl"},{line,87}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejd2sql,export,3,[{file,"src/ejd2sql.erl"},{line,85}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejd2sql,export,2,[{file,"src/ejd2sql.erl"},{line,71}]}]}
14:41:09.773 [error] Failed export for module pubsub_db and table pubsub_item: badarg
14:41:09.773 [warning] Ignoring export for module mod_push: Mnesia table push_session doesn't exist (most likely because the module is unused)
14:41:10.108 [error] SQL transaction restarts exceeded
** Restarts: 10
** Last abort reason: "#23000Duplicate entry 'elena.m-ba@rtr.host.ru-brn' for key 'i_sr_user_jid_group'"
** Stacktrace: [{ejabberd_sql,sql_query_t,1,[{file,"src/ejabberd_sql.erl"},{line,186}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{ejabberd_sql,outer_transaction,3,[{file,"src/ejabberd_sql.erl"},{line,497}]},{ejabberd_sql,run_sql_cmd,4,[{file,"src/ejabberd_sql.erl"},{line,434}]},{p1_fsm,handle_msg,10,[{file,"src/p1_fsm.erl"},{line,582}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
** When State == {state,<0.451.0>,mysql,undefined,30000,<<"rtr.host.ru">>,{{[],[]},0,1000}}
14:41:10.116 [error] Failed export for module mod_shared_roster and table sr_user: {badmatch,{aborted,"#23000Duplicate entry 'elena.m-ba@rtr.host.ru-brn' for key 'i_sr_user_jid_group'"}}
ok

Syndicate content