C
C
cehka2019-05-31 15:53:52
Django
cehka, 2019-05-31 15:53:52

How to not execute a certain piece of code during makemigrations?

It is necessary that a piece of code from __init__ of the Django application is not executed during makemigrations and other commands.
I need it because in __init__ I start a stream and when makemigrations the console just freezes, moreover, the migrations themselves do not work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2019-05-31
@cehka

It actually looks like some kind of design error...
Oh well - as a solution - add a condition to your __init__.py that will not start your process if you run makemigrations .
For example, something like this in __init__.py:

import sys

if not 'makemigrations'  in sys.argv:
   ... начинается поток ...

F
FulTupFul, 2019-05-31
@FulTupFul

If I'm not mistaken, the __init__.py file used to be used to define a folder as a namespace. He plays no role.
In order to prevent Django from fixing migrations during the makemigrations command, you can disable the application in INSTALLED_APPS for the duration of the migration.
If you do not want the model to be created in the database, then in the model settings, write:

class Foo(models.Model):
    .................
    class Meta:
        managed = false

then the model will not get into the migration

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question