Accidentally truncated res_user and lost admin user – how to recover?

Hi everyone,

I’m currently in the process of migrating data and accidentally truncated some tables, including res_user, which resulted in the deletion of the admin user.

Now, I keep getting this warning:

You are trying to read records “1” of “User” that don’t exist anymore.

Although I can still log in, this warning keeps showing up. Does anyone know how to recover or manually recreate the admin user?

Any help would be greatly appreciated!

Thanks in advance.

In your case I would create a fresh database to have as a reference, then recreate the missing records using sql in your production database.

Personally I do now know if trytond-admin could fix anything in your case, maybe try to update the database using trytond-admin? reset the password using -p flag? but only after you make a backup.

From experience: Always create a backup before doing risky manual work on a database, including recreating the records manually.

I used Trytond-admin

psycopg2.errors.ForeignKeyViolation: insert or update on table “res_user-res_group” violates foreign key constraint “res_user-res_group_user_fkey”
DETAIL: Key (user)=(1) is not present in table “res_user”.

During handling of the above exception, another exception occurred:

  File "PATH/trytond/trytond/model/modelsql.py", line 379, in __raise_integrity_error
    raise ForeignKeyError(
trytond.model.modelsql.ForeignKeyError: The value "1" for field "User" in "User - Group" does not exist. -
The above exception was the direct cause of the following exception:

Traceback (most recent call last):

  File "/path/trytond/trytond/convert.py", line 461, in parse_xmlstream
    raise Exception("Error " + self.current_state()) from e
Exception: Error In tag record model res.user-res.group with id res.user_admin_group_admin.

It keeps searching for administrator

I guess you should reinsert in the database the row of res_user with the id 1 based on the data from your backup.

thank you so muc. i will try

Be sure to keep the id as 1.

Also it is probably better to restart from your backup the migration process.

i ended up restarting with backup and making a strategy for my migration data, but the inserting an id to res_user works too! thank you.