Database already exists error in installation of bench

I am trying to re-install bench (after removing related folders from previous installation and also MariaDB) by following easy installation process. I am getting the following error-

noor@noor-RDZ:~$ sudo bash setup_frappe.sh --setup-production
Installing for Ubuntu vivid amd64
In case you encounter an error, you can post on https://discuss.frappe.io

Adding ubuntu mariadb repo
Installing packages for Ubuntu. This might take time...
Installing wkhtmltopdf
Cannot install wkhtmltodpdf. Skipping...
Adding frappe user
Installing frappe-bench
Setting up first site
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/noor/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 79, in <module>
main()
File "/home/noor/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 16, in main
click.Group(commands=commands)(prog_name='bench')
File "/home/noor/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 700, in __call__
return self.main(*args, **kwargs)
File "/home/noor/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 680, in main
rv = self.invoke(ctx)
File "/home/noor/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1027, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/noor/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1027, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/noor/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 873, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/noor/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 508, in invoke
return callback(*args, **kwargs)
File "/home/noor/frappe-bench/apps/frappe/frappe/commands.py", line 69, in new_site
_new_site(db_name, site, mariadb_root_username=mariadb_root_username, mariadb_root_password=mariadb_root_password, admin_password=admin_password, verbose=verbose, install_apps=install_app, source_sql=source_sql, force=force)
File "/home/noor/frappe-bench/apps/frappe/frappe/commands.py", line 87, in _new_site
install_db(root_login=mariadb_root_username, root_password=mariadb_root_password, db_name=db_name, admin_password=admin_password, verbose=verbose, source_sql=source_sql,force=force, reinstall=reinstall)
File "/home/noor/frappe-bench/apps/frappe/frappe/installer.py", line 31, in install_db
create_database_and_user(force, verbose)
File "/home/noor/frappe-bench/apps/frappe/frappe/installer.py", line 53, in create_database_and_user
raise Exception("Database %s already exists" % (db_name,))
Exception: Database 1bd3e0294d already exists

How can i solve the issue?

At the time of reinstalling use another site name (different than previous site name) OR Remove the database which is generated for previous site.

Geetanjali Shitole
New Indictrans Technologies Pvt. Ltd.

1 Like

@ni8mr did you remove the frappe-bench folder? The database name is chosen randomly and maybe you stumbled upon a collision.

If you delete and try again, it should work.

@anand Hello, thanks for the reply. I have tried your solution and the error has happened again.

Exception: Database 1bd3e0294d already exists

Database name is same as before. May be database name is not generating randomly in my case.

My OS is- Ubuntu Mate 1.8.2.

@Geetanjali, how can i use another site name? :expressionless: I am a beginner.

I think the db name is a hash of the site name. Fastest would be to drop that db via mysql.

1 Like

@rmehta Thank you, your suggestion has worked. But now another error has arisen.

Adding ubuntu mariadb repo
Installing packages for Ubuntu. This might take time...
Installing wkhtmltopdf
Cannot install wkhtmltodpdf. Skipping...
Adding frappe user
Installing frappe-bench
Setting up first site
Traceback (most recent call last):File "/usr/local/bin/bench", line 9, in <module>
load_entry_point('bench==0.92', 'console_scripts', 'bench')()
File "/home/noor/bench-repo/bench/cli.py", line 60, in cli
bench()
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 700, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 680, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1027, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1027, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 873, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 508, in invoke
return callback(*args, **kwargs)
File "/home/noor/bench-repo/bench/cli.py", line 459, in setup_production
_setup_production(user=user)
File "/home/noor/bench-repo/bench/production_setup.py", line 64, in setup_production
os.symlink(os.path.abspath(os.path.join(bench, 'config', 'supervisor.conf')),
os.path.join(get_supervisor_confdir(), supervisor_conf_filename))
OSError: [Errno 17] File exists

May be i should start a new thread?

I have solved the problem by resetup Ubuntu(with formatting) and than setup the framework.

This is the last and ultimate solution, but I appreciate if one can provide some steps to restore ERPNext with what-if.

There are links for nginx, supervisor, created in case of production setup.
/etc/supervisor/conf.d/frappe.conf → ~/frappe-bench/config/supervisor.conf

I believe setup_frappe.sh --setup-production is run once script.

You can follow GitHub - frappe/bench: CLI to manage Multi-tenant deployments for Frappe apps to manually install frappe-bench, create different sites and install apps manually.

@revant_one Thanks for the suggestion. I will explore it next time.

@ruchin78 That would be great. ERPNext developers should look into it. :smile:

I also faced the same problem,
What I had done is;
bench drop-site {site-name} --force
run this command in the bench directory and your site will be removed then create another one and you’re good to go!

2 Likes

This works. This is the correct answer. Thanks