Migration clashes with forms.py

前端 未结 5 537
轮回少年
轮回少年 2020-12-11 05:12

The command python manage.py makemigrations fails most of time due to the forms.py, in which new models or new fields are referenced at class defin

5条回答
  •  自闭症患者
    2020-12-11 05:56

    Thanks to @alasdair I understood my problem and found a workaround: I replace the original code in the views.py file

    from MyApp import forms
    

    with

    import sys
    if 'makemigrations' not in sys.argv and 'migrate' not in sys.argv:
        from MyApp import forms
    

    It works fine in my case, but I suppose there is a better way to know if the current process is a migration or not. If so, please advise.

提交回复
热议问题