Answer the question
In order to leave comments, you need to log in
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
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:
... начинается поток ...
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question