Will & Skill Developers

Will & Skill Developers


Thoughts, snippets and ideas from the team at Will & Skill AB, Stockholm.

Faisal Mahmud
Author

“The mind is not a vessel to be filled, but a fire to be kindled.” ― Plutarch

Share


Resetting a database in Postgres

Faisal MahmudFaisal Mahmud

Sometimes when You are trying things out and You feel that Your Django migration files are getting out of hand and You want to start clean it might be a good idea to start fresh.

Instead of truncating separate tables in a large database You can just drop the database and the recreate it.

Follow these steps

  1. Become the postgres user with sudo su postgres
  2. Jump into the psql command line tool
  3. Drop the database with drop database <YOURDBNAME>;
  4. Create the database again with create database <YOURDBNAME>;
  5. If You are using Django, recreate the database structure with python manage.py migrate

It should look something like the lines described below...

faisal@tipler:~$ sudo su postgres  
[sudo] password for faisal:
postgres@tipler:~$ psql  
psql (9.4.9)  
Type "help" for help.

postgres=# drop database django;  
DROP DATABASE  
postgres=# create database django;  
CREATE DATABASE  
postgres=#\q  
faisal@tipler:~$ python manage.py migrate  
Faisal Mahmud
Author

Faisal Mahmud

“The mind is not a vessel to be filled, but a fire to be kindled.” ― Plutarch

Comments