Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Freezing database for testing new features in Django

In my Django app, I want to add a couple of fields to my existing models and possibly create a new class. I just want to test the new feature and approve if it works.

I can revert the code using git easily. But if I make a makemigrations+migrate then my MySQL database will change and reversing the changes looks like manual deletion of tables and reverting to an old state using a command like django-admin migrate [app_label] [migration_name] (In some cases it looks really cumbersome, example).

I'm wondering if there is any safe practice to try manipulating the database and revert it back to it's initial state safely.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Probable solution #1:

You can utilize the test database that gets created when using django.test.TestCase:

Tests that require a database (namely, model tests) will not use your “real” (production) database. Separate, blank databases are created for the tests.

Create some unit tests for your project and make your migrations (without migrating to your production DB, just keep the migrations). Then:

If the database does not exist, it will first be created. Any migrations will also be applied in order to keep it up to date.

Usually, the database gets destroyed at the end of your tests, but you can keep it between runs:

You can prevent the test databases from being destroyed by using them test --keepdb option. This will preserve the test database between runs.

With this trick you can test every migration you make in a fake DB and when you do finalize your model and you have all the migrations history complete, you can migrate on your production DB.

Probable solution #2:

You can make a copy of your database as @albar suggests and have it as a back up while you are working on your new migrations.

Break stuff as much as you want and when you are set and done, replace the "battered" DB with your back up and apply your migration history to it.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!