Fix problems with migrations.

Try to cope better if things aren't exactly as we expect. e.g. deleted
accounts or LDAP entries can't be found.

Change-Id: I42131ddf53b1eeedd488fcc8c7f3f6c0f618500e