How I use frappe bench in my development workflow

Here is a list of some common commands that I use in my development workflow. This way you have some real life examples of relevant commands, which sometimes is more useful than abstract documentation. This is work in progress.

Create a new bench named development, using frappe’s develop branch and python 3.10:

bench init development --frappe-branch develop --python /usr/local/bin/python3.10
cd development/

Download ERPNext (or any other app) using the develop branch:

bench get-app --branch develop

Create a new site called “erpnext-dev” and install the app erpnext on it:

bench new-site erpnext-dev --install-app erpnext

Use “erpnext-dev” as the default site for all bench commands:

bench use erpnext-dev

Add site (defaults to erpnext-dev) to hosts, so that it points to my localhost. This way I will be able to access http://erpnext-dev:8000 with my browser.

bench add-to-hosts

Restore the backup of a production site into my dev environment:

bench restore 20220909_120002-prod-site-database.sql.gz

Migrate the restored database to match the versions of the apps in my development bench:

bench migrate

Start all services defined in Procfile:

bench start

The above process should keep running for now. Open a new terminal/window to continue.

Log in as any user:

bench browse --user Administrator

Now we can click around in our dev environment, analyse problems, create new doctypes, etc.

Pull updated code for ERPNext and make it run:

cd apps/erpnext
git pull
cd ../..
bench setup requirements  # install new dependencies
bench build  # re-build Javascript and CSS files
bench migrate  # update the database schema and run patches

After the above procedure, you should kill the process we kept running above (ctrl +c) and start it again, using bench start.

Open a python REPL that is already connected to your site’s database and has all apps loaded:

bench console

This is useful for quickly checking if, say, a call to frappe.get_list( ... ) returns all the records you would expect.


Assuming the commands are followed in order, here are some notes:

If you’re going to restore a backup to the site, you needn’t install any additional apps. Restoring a site from backup means the database is overwritten. You should be able to continue without the --install-app erpnext option.

On another note, if you name your site as {something}.localhost, you can skip the add-to-hosts step altogether. I’ve gotten by without updating the /etc/hosts file on *nix devices for a while now.