批量创建数据报错

我用代码批量创建数据,在导入model时报这个错,请问怎么解决

import os
import sys

pwd = os.path.dirname(os.path.realpath(__file__))
sys.path.append(pwd + '../')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blinks.settings')

import django

django.setup()


def main():
    from popular.models import Movie

    all_movie = Movie.objects.all()
    print(all_movie)


if __name__ == "__main__":
    main()

堆栈信息:

Traceback (most recent call last):
  File "D:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\pydevd.py", line 1758, in <module>
    main()
  File "D:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\pydevd.py", line 1752, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "D:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\pydevd.py", line 1147, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "D:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "E:/pro/code/python/blinks/db_tools/fakes.py", line 21, in <module>
    main()
  File "E:/pro/code/python/blinks/db_tools/fakes.py", line 14, in main
    from popular.models import Movie
  File "E:\pro\code\python\blinks\apps\popular\models.py", line 8, in <module>
    class Movie(models.Model):
  File "E:\pro\code\python\envs\blinks-crkym5fh\lib\site-packages\django\db\models\base.py", line 111, in __new__
    "INSTALLED_APPS." % (module, name)
RuntimeError: Model class popular.models.Movie doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

评论 1