Django 无法运行 manage.py

Posted

技术标签:

【中文标题】Django 无法运行 manage.py【英文标题】:Django not able to run manage.py 【发布时间】:2019-01-14 03:34:22 【问题描述】:

我无法在本地运行我的 Django 服务器。我正在尝试设置我的 djongo 数据库而不是默认的 sqlite3 .db

这里我按照下面的 URL 设置了 djongodjongo on python

System check identified no issues (0 silenced).
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7fb554b61bf8>
Traceback (most recent call last):
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run
    self.check_migrations()
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/django/core/management/base.py", line 442, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/django/db/migrations/loader.py", line 209, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 61, in applied_migrations
    if self.has_table():
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 44, in has_table
    return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/django/db/backends/base/introspection.py", line 56, in table_names
    return get_names(cursor)
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/django/db/backends/base/introspection.py", line 51, in get_names
    return sorted(ti.name for ti in self.get_table_list(cursor)
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/djongo/introspection.py", line 34, in get_table_list
    for c in cursor.db_conn.collection_names(False)]
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/pymongo/database.py", line 715, in collection_names
    nameOnly=True, **kws)]
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/pymongo/database.py", line 674, in list_collections
    read_pref) as (sock_info, slave_okay):
  File "/home/iradmin/anaconda3/lib/python3.6/contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1099, in _socket_for_reads
    server = topology.select_server(read_preference)
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/pymongo/topology.py", line 224, in select_server
    address))
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/pymongo/topology.py", line 183, in select_servers
    selector, server_timeout, address)
  File "/home/iradmin/anaconda3/lib/python3.6/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
    self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused

我在这里包含了我的 setting.py 供您参考。

DATABASES = 
  'default' : 
    'ENGINE' : 'djongo',
    'NAME' : 'my_database'
  


INSTALLED_APPS = [
    'polls',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

【问题讨论】:

Why is PyMongo 3 giving ServerSelectionTimeoutError?的可能重复 【参考方案1】:

您在连接数据库时是否包含了USERPASSWORD?由于错误为connection refused,您可能需要将凭据包含到您的数据库设置中,例如USERPASSWORD

例如,

DATABASES = 
    'default' : 
        'ENGINE' : 'djongo',
        'NAME' : 'my_database',
        'USER' : 'db-username',
        'PASSWORD': 'db-password'
    

如果没有,可以参考以下Pymongo keeps refusing the connection at 27017

【讨论】:

以上是关于Django 无法运行 manage.py的主要内容,如果未能解决你的问题,请参考以下文章

Django manage.py runserver无法打开浏览器

Django 无法导入本地设置

python 无法打开文件'manage.py'-“heroku 运行 python manage.py 迁移命令输入”

什么时候应该使用 django-admin.py 和 manage.py?

关于Django无法启动数据库和无法命令行启动manage.py的解决方法

Django Heroku:python:无法打开文件'manage.py':[Errno 2]没有这样的文件或目录