(env3.6.6) mac126@ubuntu:~/Desktop/13/day3-1$ python manage.py db init Traceback (most recent call last): File "manage.py", line 13, in <module> manage.run() File "/home/mac126/.pyenv/versions/3.6.6/envs/env3.6.6/lib/python3.6/site-packages/flask_script/__init__.py", line 417, in run result = self.handle(argv[0], argv[1:]) File "/home/mac126/.pyenv/versions/3.6.6/envs/env3.6.6/lib/python3.6/site-packages/flask_script/__init__.py", line 386, in handle res = handle(*args, **config) File "/home/mac126/.pyenv/versions/3.6.6/envs/env3.6.6/lib/python3.6/site-packages/flask_script/commands.py", line 216, in __call__ return self.run(*args, **kwargs) File "/home/mac126/.pyenv/versions/3.6.6/envs/env3.6.6/lib/python3.6/site-packages/flask_migrate/__init__.py", line 95, in wrapped f(*args, **kwargs) File "/home/mac126/.pyenv/versions/3.6.6/envs/env3.6.6/lib/python3.6/site-packages/flask_migrate/__init__.py", line 125, in init directory = current_app.extensions['migrate'].directory KeyError: 'migrate'
看到这个错误,对于一个新手来说那是充满恐惧的,不知道怎么去解决,首先想到的一个工具应该是百度,万能的百度。不过百度有的时候查到的问题和自己的情况不一样,那就综合起来看看自己的代码是不是有问题。
上面这个init_ext(app)这个函数需要添加到__init__.py文件里面,即可解决KeyError: 'migrate'错误