XF 2.2 After upgrading to 2.2.20 (2026.11) - error when searching for users

Alan_SP

Well-known member
Licensed customer
I have error after upgrading to 2.2.20, latest patch.

After that I had issues with restoring forum, you can read about it here.

As it unlocked by itself, I tried to upgrade again, and this is the error I have when searching for users (in CP and when it's done in front end):


  • XF\Db\InvalidQueryException: MySQL statement prepare error [1176]: Key 'username' doesn't exist in table 'xf_user'
  • src/XF/Db/AbstractStatement.php:230
  • Generated by: Alan_SP
  • Sunday - 29.11.2026 at 20:36:56

Code:
Stack trace
            SELECT `xf_user`.*
            FROM `xf_user` IGNORE INDEX (`username`)
           
           
            ORDER BY `xf_user`.`username` ASC
       
LIMIT 20
------------

#0 src/XF/Db/Mysqli/Statement.php(198): XF\Db\AbstractStatement->getException('MySQL statement...', 1176, '42000')
#1 src/XF/Db/Mysqli/Statement.php(40): XF\Db\Mysqli\Statement->getException('MySQL statement...', 1176, '42000')
#2 src/XF/Db/Mysqli/Statement.php(56): XF\Db\Mysqli\Statement->prepare()
#3 src/XF/Db/AbstractAdapter.php(106): XF\Db\Mysqli\Statement->execute()
#4 src/XF/Mvc/Entity/Finder.php(1428): XF\Db\AbstractAdapter->query('
            SELECT `xf_...')
#5 src/XF/Admin/Controller/User.php(116): XF\Mvc\Entity\Finder->fetch()
#6 src/XF/Admin/Controller/User.php(32): XF\Admin\Controller\User->getListData(false, NULL)
#7 src/XF/Mvc/Dispatcher.php(352): XF\Admin\Controller\User->actionList(Object(XF\Mvc\ParameterBag))
#8 src/XF/Mvc/Dispatcher.php(258): XF\Mvc\Dispatcher->dispatchClass('XF:User', 'List', Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\User), NULL)
#9 src/XF/Mvc/Dispatcher.php(115): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\User), NULL)
#10 src/XF/Mvc/Dispatcher.php(57): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#11 src/XF/App.php(2523): XF\Mvc\Dispatcher->run()
#12 src/XF.php(524): XF\App->run()
#13 admin.php(13): XF::runApp('XF\\Admin\\App')
#14 {main}

Code:
Request state
array(4) {
  ["url"] => string(27) "/forum/admin.php?users/list"
  ["referrer"] => string(42) "https://exiledkingdoms.com/forum/admin.php"
  ["_GET"] => array(1) {
    ["users/list"] => string(0) ""
  }
  ["_POST"] => array(0) {
  }
}

I'm not sure if it's something simple, but it is been repeated on second upgrade attempt.

I did successfully upgraded smaller forum where I can search for users and there searching for users works, as far as I can say. But, on this particular one, with more data, this consistently happens
 
Automated triage: Awaiting feedback

Thank you for reporting this issue. The error means the database's user table is missing a standard index on the username column. A normal install creates that index and no upgrade removes it, so something on this particular database appears to have lost it. We need a little more detail to look into this.

  • Please run SHOW INDEX FROM xf_user; (or SHOW CREATE TABLE xf_user;) on this database and post the output. Does it list a unique key named 'username'?
  • Which XenForo version did this forum upgrade from, and did the admin user list work on that version before the upgrade?
  • How was the database backup made and restored (which tool or command)? Was the xf_user table recreated during the restore?
  • Which add-ons are installed, especially the one that showed errors about missing user data, and do any of them alter the xf_user table?
  • What is the exact error (full server error log entry) when searching for members on the front end?

This is an automated assessment. A member of staff may review and update it.
 
The bot is correct but this isn’t a bug and will require troubleshooting and potentially manual actions to resolve, some troubleshooting steps have been provided.

It does appear as though your xf_user table is missing its unique index on the username column.
 
If you're willing to work with me for a bit, I can upgrade again (for the third time).

I now did restore forum again (I upgraded it from 2.2.9) and I again have the message that forum is in upgrade process.

I can confirm that when I tested restored (2.2.9) version, everything worked fine. I will retest again, as soon as I can work with the forum.
 
Is there something I should do prior upgrading forum? Let's test for some DB issues prior upgrading, just to see why it doesn't work after upgrade.

Please, let me know for what I have to check
 
We’ve reached the extent I’m able to help unfortunately. XenForo 2.2 is no longer supported. The bot message has some things to check.

All I can confirm is that there isn’t a bug and the issue is either with the backup or restore process.

We recommend upgrading to XenForo 2.3 to ensure you’re using a supported version.
 
I'm waiting for upgrade process lock to be finished, so I can check if everything is okay. But, I did test searching for users after first restoring. It worked then
 
Yes that confirms the username index is missing. Your database is not in a state that is consistent with what it should be and should be resolved.
 
Okay, I ran query on forum where upgrade went smoothly, and I do see the difference. The big one.

Anyone can help me how to recreate right structure of xf_user table?

I guess that when we transferred to KnownHost, that happened, or even more likely, while we still where on A2 hosting (now just hosting), they tried to transfer us to another server from them. There were many issues in that process. And this might be from that time
 

Attachments

  • 1.webp
    1.webp
    63.3 KB · Views: 6
But really you would be very wise to spend the time looking into why the index is not there.

This may be just one of many issues that could surface if other indexes are missing.
 
Thank you very much. It's really nice of you and I appreciate it.

I think it happened when A2 hosting (mentioned above) was transferring us from one of their servers to another. We did had a lot of issues back then, they tried to move us few times. Some of issues I fixed with the help of community. It looks that at least one issue was still there.

Now I used help of AI and working table on my other forum and I used this code to fix table:

Code:
ALTER TABLE `xf_user`
  MODIFY `user_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  ADD UNIQUE KEY `username` (`username`),
  ADD KEY `email` (`email`),
  ADD KEY `permission_combination_id` (`permission_combination_id`),
  ADD KEY `user_state` (`user_state`),
  ADD KEY `last_activity` (`last_activity`),
  ADD KEY `last_summary_email_date` (`last_summary_email_date`),
  ADD KEY `message_count` (`message_count`),
  ADD KEY `trophy_points` (`trophy_points`),
  ADD KEY `reaction_score` (`reaction_score`),
  ADD KEY `register_date` (`register_date`),
  ADD KEY `question_solution_count` (`question_solution_count`),
  ADD KEY `vote_score` (`vote_score`),
  ADD KEY `staff_username` (`is_staff`, `username`);

The code is a bit different. After I visually compared DBs and tested if everything works, I went and did upgrade to 2.2.20. And then again tested a lot of things (moderation, addons, writing, registering...) everything seems fine and there are no server errors in log after testing.

It does seem that A2 hosting (now they are just hosting) really did poor job in transferring us from one of their servers to another of their servers. Terrible service. That's why we are with KnownHost now.

Anyway, if something crops up, I guess it's related to this too.
 
Back
Top Bottom