modoboa/modoboa-pfxadmin-migrate

Migration fails with "Cannot resolve keyword u'domain' into field. Choices are: active, created, modified, password, username"

derfischi opened this issue · 10 comments

Migration fails with the error / stacktrace below. I'm using Postfixadmin 2.3.7.

Migrating domain example.com
Migrating domain aliases
Migrating mailboxes
Migrating mailbox aliases
Migrating administrators
Traceback (most recent call last):
File "./manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/dist-packages/django/core/management/init.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/dist-packages/django/core/management/init.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(_args, *_options.dict)
File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute
output = self.handle(_args, _options)
File "/usr/local/lib/python2.7/dist-packages/modoboa_pfxadmin_migrate-1.0.0-py2.7.egg/modoboa_pfxadmin_migrate/management/commands/migrate_from_postfixadmin.py", line 291, in handle
self._do_migration(options)
File "/usr/local/lib/python2.7/dist-packages/modoboa_pfxadmin_migrate-1.0.0-py2.7.egg/modoboa_pfxadmin_migrate/management/commands/migrate_from_postfixadmin.py", line 281, in _do_migration
self._migrate_domain(pf_domain, options, creator)
File "/usr/local/lib/python2.7/dist-packages/modoboa_pfxadmin_migrate-1.0.0-py2.7.egg/modoboa_pfxadmin_migrate/management/commands/migrate_from_postfixadmin.py", line 204, in _migrate_domain
self._migrate_admins(options, creator, pf_domain, newdom)
File "/usr/local/lib/python2.7/dist-packages/modoboa_pfxadmin_migrate-1.0.0-py2.7.egg/modoboa_pfxadmin_migrate/management/commands/migrate_from_postfixadmin.py", line 221, in _migrate_admins
for old_admin in pf_domain.admins.all():
File "/usr/lib/python2.7/dist-packages/django/db/models/manager.py", line 191, in all
return self.get_queryset()
File "/usr/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 885, in get_queryset
return qs._next_is_sticky().filter(
_self.core_filters)
File "/usr/lib/python2.7/dist-packages/django/db/models/query.py", line 691, in filter
return self._filter_or_exclude(False, *args, *_kwargs)
File "/usr/lib/python2.7/dist-packages/django/db/models/query.py", line 709, in _filter_or_exclude
clone.query.add_q(Q(_args, *_kwargs))
File "/usr/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1331, in add_q
clause, require_inner = self._add_q(where_part, self.used_aliases)
File "/usr/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1358, in _add_q
current_negated=current_negated, connector=connector)
File "/usr/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1182, in build_filter
lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "/usr/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1120, in solve_lookup_type
_, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
File "/usr/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1427, in names_to_path
self.raise_field_error(opts, name)
File "/usr/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1433, in raise_field_error
"Choices are: %s" % (name, ", ".join(available)))
django.core.exceptions.FieldError: Cannot resolve keyword u'domain' into field. Choices are: active, created, modified, password, username

I have the same issue.

Which version of postfixadmin ?

@tonioo it is 2.3.5.

@spron-in Could you try this patch please ?

@tonioo done, now I get the following:

python manage.py migrate_from_postfixadmin -s md5crypt

Migrating domain example.com
    Migrating domain aliases
    Migrating mailboxes
    Migrating mailbox aliases
    Migrating administrators
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 385, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, 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 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/modoboa_pfxadmin_migrate-1.0.0-py2.7.egg/modoboa_pfxadmin_migrate/management/commands/migrate_from_postfixadmin.py", line 294, in handle
    self._do_migration(options)
  File "/usr/local/lib/python2.7/dist-packages/modoboa_pfxadmin_migrate-1.0.0-py2.7.egg/modoboa_pfxadmin_migrate/management/commands/migrate_from_postfixadmin.py", line 284, in _do_migration
    self._migrate_domain(pf_domain, options, creator)
  File "/usr/local/lib/python2.7/dist-packages/modoboa_pfxadmin_migrate-1.0.0-py2.7.egg/modoboa_pfxadmin_migrate/management/commands/migrate_from_postfixadmin.py", line 204, in _migrate_domain
    self._migrate_admins(options, creator, pf_domain, newdom)
  File "/usr/local/lib/python2.7/dist-packages/modoboa_pfxadmin_migrate-1.0.0-py2.7.egg/modoboa_pfxadmin_migrate/management/commands/migrate_from_postfixadmin.py", line 223, in _migrate_admins
    for old_permission in qset.all():
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 141, in __iter__
    self._fetch_all()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 966, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 265, in iterator
    for row in compiler.results_iter():
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 701, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 787, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 94, 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 65, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 129, 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.ProgrammingError: (1146, "Table 'modoboa.domain_admins' doesn't exist")

I guess it is my bad and will have a look. admin_domain is there, but domain_admins is really absent.

Looks like your configuration is wrong. What is the content of you settings.py file ? (DATABASES variable)

It is smth like this:

DATABASES = {

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'modoboa',
        'USER': 'modoboa_rw',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '3306',
        'ATOMIC_REQUESTS': True,
        'OPTIONS' : {
            "init_command" : 'SET foreign_key_checks = 0;',
        },
    },

    "pfxadmin" : {
        "ENGINE" : "django.db.backends.mysql",
        "NAME" : "postfix_migrate",
        "USER" : "postfix_migrate",
        "PASSWORD" : "",
    }
}

My bad, I forgot something. Can you test once again please ?

@tonioo works like a charm! Thank you :)

Great news :)