Can’t add users in admin after copying database

The key turned out to be that the wp_users table lost its AUTO_INCREMENT setting when it was imported, for unknown reasons; the server may have timed out, etc.

I found this out from the wp-cli error in the debug log that said "WordPress database error Duplicate entry '1000075' for key 'PRIMARY' for query INSERT INTO 'wp_users'and in PHPMyAdmin, I could see that the ID 1000075 was already assigned to a user.

Even though the wp_users table showed AUTO_INCREMENTset in PHPMyAdmin, I ran this query to set it anyway:

ALTER TABLE pw_users AUTO_INCREMENT = last-ID-plus-1

where last-ID-plus-1 is the highest ID that exists in wp_users, plus 1, i.e. in my case was

ALTER TABLE pw_users AUTO_INCREMENT = 1003000

After setting AUTO_INCREMENT, I can add users.

Reference: @N00b’s answer for WordPress Database lost auto increment