Crash with "Duplicate entry" error
yannfill opened this issue · 3 comments
yannfill commented
The script starts migrating several domains and then crashes:
Migrating domain example.org
Migrating domain aliases
Migrating mailboxes
Migrating mailbox aliases
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/modoboa_pfxadmin_migrate/management/commands/migrate_from_postfixadmin.py", line 288, in handle
self._do_migration(options)
File "/usr/local/lib/python2.7/dist-packages/modoboa_pfxadmin_migrate/management/commands/migrate_from_postfixadmin.py", line 278, in _do_migration
self._migrate_domain(pf_domain, options, creator)
File "/usr/local/lib/python2.7/dist-packages/modoboa_pfxadmin_migrate/management/commands/migrate_from_postfixadmin.py", line 198, in _migrate_domain
self._migrate_mailbox_aliases(newdom, options, creator)
File "/usr/local/lib/python2.7/dist-packages/modoboa_pfxadmin_migrate/management/commands/migrate_from_postfixadmin.py", line 160, in _migrate_mailbox_aliases
options["_to"]).bulk_create(to_create)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 450, in bulk_create
self._batched_insert(objs_without_pk, fields, batch_size)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 1056, in _batched_insert
using=self.db)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 1039, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 1060, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 112, in execute
return self.cursor.execute(query, args)
File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.IntegrityError: (1062, "Duplicate entry '1628-1148' for key 'modoboa_admin_aliasrecipient_alias_id_c005be7e_uniq'")
tonioo commented
I'd say you have a duplicated alias in your postfixadmin database... would it be possible?
yannfill commented
I didn't find any in the alias table:
mysql> USE postfixadmin;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select address, COUNT(*) count FROM alias GROUP BY address HAVING count > 1;
Empty set (0.00 sec)
yannfill commented
In fact there was a duplicate: I find out that in the alias table, each address is assigned the same same address as alias when there is no alias defined. It turned out that for one adress, the alias was the same address, but added twice. Fixing this made the script run as expected.
Thanks for pointing me to the right place to look at.