How to deploy a database from development to production?

Hi all! Please I have two working environments development and production. I tried to use the backup and restore system respectively with the commands $ bench backup on the development environment and $ bench restore on the production. With this method what happens is that all my production data is replaced by the data that arrives from the development environment, so we lose all the production records (users, etc…).

What we want is to version so that we keep the existing data and add if needed the data coming from the dev.

Please could someone help here?

Thanks in advance.

What kind of data do you work with on the development environment that needs to be moved?

Generally it is the code or the changes (such as fields, documents, etc) that need to move through the environments as the data on production will be considered as the source of truth.

We are working mostly on data from the website, education and association modules.

That’s exactly what I want but that’s not what’s happening right now.

hello @TNHD_Pro,

I assume you’re talking about your customization’s in your system? or not?

Hi @kkulloters ,

I’m not sure if I understood your question.

My problem is to do a restore without losing the existing data on my target environment.

Hi @TNHD_Pro,

If I understand your requirements correctly:

  • You have data in both Development and Production.
  • You want to take any additional data that exists in Development, and -append- that data to what is already in Production.
  • Without losing or overwriting your data in Production. Just adding to what is already there.

Is this a correct summary?


Thank you @brian_pond

Very good summary that’s exactly what I want.

bench restore will wipe out all existing data and add new data.

You will have to manually add (via data import) either production or development information. I don’t recall that there is a straight forward update to existing information.

Agree with @Muzzy: the only way to accomplish this is manually.

For a tool to accomplish this automatically, there would be huge complexity and risk. How would it know which records to copy, and which to leave behind? How will it understand merge scenarios?

For example, assume the following:

  • Development has a Supplier named “Acme Anvil Manufacturing, Inc.”.
  • Production has a Supplier named “Acme Anvil Mfg, Inc.”.
  • Is this the same Supplier, or two different ones? How does the migration tool know the rules?
  • If they are the same, but certain attributes are different (e.g. Payment Terms, Address), which attribute is the correct one for Production?

There are hundreds of other small challenges: Customizations, DocTypes that are Singles, Versions, User defaults, environment-specific defaults like Keys and Secrets, and more. Also, what if the MySQL table schemas are different between Development and Production?

I’ve never seen any ERP accomplish something like this. Instead, people manually design and develop custom scripts for their particular database + requirements.

Even an automated tool for copying the other direction (Production —> Development) is not always easy. I’ve been asked to build something like this for a client. Great care must be taken to ensure that your Development environment’s database is reconfigured, to behave correctly (e.g. disable automation so the Development environment does not send emails to real customers, employees, APIs, etc.)


So what is the deal with this situation?!
How do you guys manage the development and production environments with ERPnext?
I’m searching for a while about the exact subject, I’m a business user, not a developer. I just consulted some of my close developers that don’t know what ERPnext is, they just working on many other frameworks and they explain to me the approach of having a development and production environment.
They said you should create a development environment in the beginning, and work on it, once that is ready for production, you should convert it to production, and then you will have a copy of that production environment to consider it as a development, then work on it, and once you are ready with your new features and updates, you just migrate the development (changes) to the production, and repeat the cycle.
And in regards to the data, all of these migrations are for the application not for the data.

This is how I understand it.

But it seems there is another approach that ERPnext community is using, which I don’t understand yet!

So, could someone explain the mystery behind that subject?

@adelalmajed that’s exactly what we do . there is no other approach.

Okay, that’s great!
How to do it?

I have two containers (srv1 & db1) and they are both active and running, how to get a copy from these containers for development?
Then how to migrate the development containers to the production?

@adelalmajed using custom apps of course . create a custom app . save all your customization or new features into the app . push it to github . and then you can install it on other servers .
check this topic about custom apps .
if you want to copy the database itself . use backup and restore .

Thank you @bahaou for the answer.
Unfortunately, it’s not what I’m looking for, perhaps I didn’t explain it well.
I’m talking about cloning a production environment where I have two exact running instances, and the main idea is to modify some documents and test the workflows before migrating them to the production.

I found the following question which is exactly what I’m looking for, but unfortunately, no one answers his question! :frowning:

@adelalmajed I did understood your question and my answer still the same . you have two running instances , one is dev and the otehr is production . you want to do your work in the dev instances , test it and then migrate it to the production server . that’s exactly what custom apps do

Thank you @bahaou

While reading the link you provided, I don’t know why I felt it is a method of creating a separate app! It seems like creating a new module or something needs to be coded, while my need is to implement the business workflows and permissions on the existing ERPnext modules.
However, after reading your confirmation, I felt it was my fault for judging something I didn’t try yet.
Therefore, I will start learning the method you have suggested, and I hope it is easy to learn.
If you have more examples or tutorials for that methods, please share them with us.

Many thanks

@adelalmajed you can indeed add new modules in the app . but it also provide the possibility to save customization and everything you have changed. example you changed some permissions and workflows for sales order . you export them to the app . after installing the app to a new server . all custom changes will appear .

Very nice, that’s exactly what I need.
But what about creating a clone of the production? the link you provide seems to dive into the customization method directly.

From the beginning, I thought there is a bench command that makes everything, for example:
bench --site production_site.local create development_site.local
and after that, a new site will be created alongside the existing one. And when completing the customization of development_site.local, we just run:
bench --site development_site.local migrate-to production_site.local

Isn’t that would be great?