从命令行运行django数据库操作

从命令行运行django数据库操作,报错:

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

看settings.py没有问题

解决的方法:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

注意这个是不行的:
from django.conf import settings
settings.configure()

两者都写也是不行的

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。