Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda