DEV Community

Reishi Mitani
Reishi Mitani

Posted on

What to Do When You Accidentally Drop a Database in a Docker Environment

Today I accidentally dropped the mysql table django_admin_log in my docker + django environment. I both have django and mysql running in the docker container.

First, I used the following command.

docker-compose run --rm api python timeline/manage.py sqlmigrate admin 0001

CREATE TABLE `django_admin_log` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `action_time` datetime(6) NOT NULL, `object_id` longtext NULL, `object_repr` varchar(200) NOT NULL, `action_flag` smallint UNSIGNED NOT NULL, `change_message` longtext NOT NULL, `content_type_id` integer NULL, `user_id` integer NOT NULL);
Enter fullscreen mode Exit fullscreen mode

Although the message above indicates that it has created the table, I did not see any difference in my database server.
So after copying the sql sentence above, I entered the mysql container, and booted up mysql.
Inside mysql, I pasted the message from above.

$ docker exec -it db-container /bin/bash
# mysql
> CREATE TABLE `django_admin_log` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `action_time` datetime(6) NOT NULL, `object_id` longtext NULL, `object_repr` varchar(200) NOT NULL, `action_flag` smallint UNSIGNED NOT NULL, `change_message` longtext NOT NULL, `content_type_id` integer NULL, `user_id` integer NOT NULL);
Enter fullscreen mode Exit fullscreen mode

This recreated the table in my database server.

Top comments (0)