# Error restoring from backup

**URL:** <https://www.dolibarr.org/forum/t/error-restoring-from-backup/22199>\
**Category:** Using my Dolibarr\
**Tags:** Linux\
**Created:** [April 19, 2022, 12:14am UTC](https://www.dolibarr.org/forum/t/error-restoring-from-backup/22199 "2022-04-19T00:14:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![galvatec](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@galvatec](https://www.dolibarr.org/forum/u/galvatec)\
**Post date:** [April 19, 2022, 12:14am UTC](https://www.dolibarr.org/forum/t/error-restoring-from-backup/22199/1 "2022-04-19T00:14:27Z")

</div>

I need to migrate server and so I installed version 15.0.1 on my new server and I use version 13.0.0 on the old server and when I go to restore the backup of the old server I get the error:

Error  
SQL Command:

CREATE TABLE `llx_adherent_type` (  
`rowid` int(11) NOT NULL,  
`entity` int(11) NOT NULL DEFAULT ‘1’,  
`tms` timestamp NOT NULL DEFAULT CURRENT\_TIMESTAMP ON UPDATE CURRENT\_TIMESTAMP,  
`statut` smallint(6) NOT NULL DEFAULT ‘0’,  
`libelle` varchar(50) NOT NULL,  
`morphy` varchar(3) NOT NULL,  
`duration` varchar(6) DEFAULT NULL,  
`subscription` varchar(3) NOT NULL DEFAULT ‘yes’,  
`vote` varchar(3) NOT NULL DEFAULT ‘yes’,  
`note` text,  
`mail_valid` text  
) ENGINE=InnoDB DEFAULT CHARSET=utf8  
MySQL Messages : Documentation

#1005 - Cannot create table `dolibarr`.`llx_adherent_type` (error no. 150 “Foreign key constraint is incorrectly formed”) (Information…)

---

<div class="post-metadata">

**Author:** ![simicar](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/simicar/32/3072_2.png) [@simicar](https://www.dolibarr.org/forum/u/simicar)\
**Post date:** [April 19, 2022, 5:30am UTC](https://www.dolibarr.org/forum/t/error-restoring-from-backup/22199/2 "2022-04-19T05:30:41Z")

</div>

Hi, try restoring your backup without foreign key verification.  
Hope that helps.  
Regards,  
Marc

---

<div class="post-metadata">

**Author:** ![galvatec](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@galvatec](https://www.dolibarr.org/forum/u/galvatec)\
**Post date:** [April 24, 2022, 9:56pm UTC](https://www.dolibarr.org/forum/t/error-restoring-from-backup/22199/3 "2022-04-24T21:56:19Z")

</div>

I performed the restore without the foreign key verification but the error remains

I would like to understand why this error occurs with several tables

#1005 - Cannot create table `dolibarr` .`llx_adherent_type` (error no. 150 “Foreign key constraint is incorrectly formed”) (Information…)

---

<div class="post-metadata">

**Author:** ![priojk](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/priojk/32/6121_2.png) [@priojk](https://www.dolibarr.org/forum/u/priojk)\
**Post date:** [April 25, 2022, 6:46pm UTC](https://www.dolibarr.org/forum/t/error-restoring-from-backup/22199/4 "2022-04-25T18:46:53Z")

</div>

I would try restoring a backup to the exact version it was created from, i.e. if it was created with version 13.0.0 I would restore it to a Dolibarr system of the same version 13.0.0 and migrate to 15.0.1 after the backup was successfully imported.

---

<div class="post-metadata">

**Author:** ![galvatec](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@galvatec](https://www.dolibarr.org/forum/u/galvatec)\
**Post date:** [May 12, 2022, 8:47pm UTC](https://www.dolibarr.org/forum/t/error-restoring-from-backup/22199/5 "2022-05-12T20:47:52Z")

</div>

Hello I did this, I installed the same version of Dollibarr but when restoring the same error, by PHPMyadmin and by the command line.

---

<div class="post-metadata">

**Author:** ![galvatec](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@galvatec](https://www.dolibarr.org/forum/u/galvatec)\
**Post date:** [May 12, 2022, 11:14pm UTC](https://www.dolibarr.org/forum/t/error-restoring-from-backup/22199/6 "2022-05-12T23:14:53Z")

</div>

Now I have this error when restoring the backup I use version 15.0.1 on both the old and the new Dolibarr

ERROR 1822 (HY000) at line 1324: Failed to add the foreign key constraint. Missing index for constraint ‘fk\_adherent\_adherent\_type’ in the referenced table ‘llx\_adherent\_type’

---

<div class="post-metadata">

**Author:** ![priojk](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/priojk/32/6121_2.png) [@priojk](https://www.dolibarr.org/forum/u/priojk)\
**Post date:** [May 13, 2022, 6:36am UTC](https://www.dolibarr.org/forum/t/error-restoring-from-backup/22199/7 "2022-05-13T06:36:59Z")

</div>

I just had a look at the respective part in a backup from Dolibarr version 15.0.1:

```auto
--
-- Table structure for table `llx_adherent_type`
--

DROP TABLE IF EXISTS `llx_adherent_type`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `llx_adherent_type` (
  `rowid` int NOT NULL AUTO_INCREMENT,
  `entity` int NOT NULL DEFAULT '1',
  `tms` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `statut` smallint NOT NULL DEFAULT '0',
  `libelle` varchar(50) NOT NULL,
  `morphy` varchar(3) NOT NULL,
  `duration` varchar(6) DEFAULT NULL,
  `subscription` varchar(3) NOT NULL DEFAULT '1',
  `amount` double(24,8) DEFAULT NULL,
  `vote` varchar(3) NOT NULL DEFAULT '1',
  `note` text,
  `mail_valid` text,
  PRIMARY KEY (`rowid`),
  UNIQUE KEY `uk_adherent_type_libelle` (`libelle`,`entity`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

```

As you can see, there are two additional lines and an AUTO\_INCREMENT is missing from your dump:

```auto
  PRIMARY KEY (`rowid`),
  UNIQUE KEY `uk_adherent_type_libelle` (`libelle`,`entity`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 

```

You could try adding these lines into the backup file and see, if this solves the issue. However, there is probably some other underlying issue which causes this. For instance, you are also missing the field amount. Did you have any trouble in the past while performing a migration to a newer release?

There is still an additional option. Dolibarr comes with a repair script for the database: /install/repair.php More info can be found on this page: [Troubleshooting - Dolibarr ERP CRM Wiki](https://wiki.dolibarr.org/index.php?title=Troubleshooting)

You can try your luck with it. BUT: It is good to have a (working) backup before doing this, which is not the case in your scenario. So you may want to take a server snapshot or do whatever can guarantee to be able to roll back to the state before running the script.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![heman](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/h/e495f1/32.png) [@heman](https://www.dolibarr.org/forum/u/heman)\
**Post date:** [March 16, 2023, 4:12pm UTC](https://www.dolibarr.org/forum/t/error-restoring-from-backup/22199/8 "2023-03-16T16:12:48Z")

</div>

Not sure if this helps but, for me, I had this issue when I was trying to populate demo data - more or less, the same function - restoring the database. I came across [Rrestore db from server to localhost (XAMPP)](https://www.dolibarr.org/forum/t/rrestore-db-from-server-to-localhost-xampp/18227) and realized that dropping and recreating the database is a solution. In my case, I simply dropped all the tables in the DB and ran the script although in your case, I am assuming there are anyways no tables in the DB. Your issue is most probably resolved by now but I am hoping this helps someone who comes across the thread

---

<div class="post-metadata">

**Author:** ![strk](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/strk/32/8397_2.png) [@strk](https://www.dolibarr.org/forum/u/strk)\
**Post date:** [March 10, 2025, 4:58am UTC](https://www.dolibarr.org/forum/t/error-restoring-from-backup/22199/9 "2025-03-10T04:58:58Z")

</div>

Is it supposed to be possible to do full backup of a 20.0 version and restore it in a 21.0 version ? I’d like to test the software on the hosted demo instances bit hadn’t found a way to do this

---

<div class="post-metadata">

**Author:** ![strk](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/strk/32/8397_2.png) [@strk](https://www.dolibarr.org/forum/u/strk)\
**Post date:** [March 10, 2025, 5:32am UTC](https://www.dolibarr.org/forum/t/error-restoring-from-backup/22199/10 "2025-03-10T05:32:05Z")

</div>

I found the menu items (was confused by the menu disappearing upon selecting a macro area) and was able to obtain an export of the MySQL database and the data directory, but I don’t see a way to restore those backups from the web UI. Do I need to enable some module to do that ?

---

<div class="post-metadata">

**Author:** ![dhinnewinkel](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/d/90db22/32.png) [@dhinnewinkel](https://www.dolibarr.org/forum/u/dhinnewinkel)\
**Post date:** [July 28, 2026, 8:44pm UTC](https://www.dolibarr.org/forum/t/error-restoring-from-backup/22199/11 "2026-07-28T20:44:18Z")

</div>

Hi ,

I had the same problem, and resolved it by reading this document : [Restores - Dolibarr ERP CRM Wiki](https://wiki.dolibarr.org/index.php/Restores)

 ![image](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/f/fba46e8c8e3d1ccd53fa93bc77ab882721553486.png)

---

<div class="post-metadata">

**Author:** ![jonbendtsen](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jonbendtsen](https://www.dolibarr.org/forum/u/jonbendtsen)\
**Post date:** [September 4, 2026, 4:02pm UTC](https://www.dolibarr.org/forum/t/error-restoring-from-backup/22199/12 "2026-09-04T16:02:35Z")

</div>

The way I test upgrades with production data before upgrading production is to start my mariadb container initializing the data with the backup file from Dolibarr.

> **[mariadb - Official Image | Docker Hub](https://hub.docker.com/_/mariadb#initializing-the-database-contents)**
>
> MariaDB Server is a high performing open source relational database, forked from MySQL.

```auto
Initializing the database contents
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql, .sql.gz, .sql.xz and .sql.zst that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. .sh files without file execute permission are sourced rather than executed. You can easily populate your mariadb services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by the MARIADB_DATABASE variable.

```

I’ve created some shell scripts that you can get here [GitHub - JonBendtsen/dolibarr\_devtainer: Development container setup for dolibarr · GitHub](https://github.com/JonBendtsen/dolibarr_devtainer/tree/main)

I use it for my development setup where I can easily run several versions of different dolibarrs all using their own mariadb container which is initialized with the method I mention above
