DEV Community

Reishi Mitani
Reishi Mitani

Posted on

1

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.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay