How to drop and create a database in Docker — Part 1
I am a Django developer and from time to time we work on projects that interact with the database. This is where the Django ORM comes in, it helps the developer to create and update database tables.
In order to create an environment that closely mimics that of the production environment on my local machine, I use Docker to containerize my project.
However, there are times you can have some challenges when you make migrations and for some reason, they are all mixed up and you get errors that you feel the best thing to do is to drop the database and create it again. This is ideal if you are working on a new project or you have already backed up your data.
It is usually confusing how to go about dropping and creating a database in Docker. One way to go about this is to use the exec
command. A typical docker-compose file will look like the following:
This is a simple docker-compose file with just two services — web
and db
.