运行“python manage.py runserver”时无法连接到MySQL数据库

时间:2016-12-02 03:33:41

标签: python mysql django python-2.7 django-models

输入以下内容后:

(djangoEnv)manwe:djangofriends scott $ python manage.py runserver

我收到以下回溯错误:

执行系统检查......

Unhandled exception in thread started by <function wrapper at 0x10ac12ed8>
Traceback (most recent call last):
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
    self.check(display_num_errors=True)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/core/management/base.py", line 374, in check
    include_deployment_checks=include_deployment_checks,
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/core/management/base.py", line 361, in _run_checks
    return checks.run_checks(**kwargs)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/core/checks/model_checks.py", line 30, in check_all_models
    errors.extend(model.check(**kwargs))
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/models/base.py", line 1266, in check
    errors.extend(cls._check_fields(**kwargs))
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/models/base.py", line 1337, in _check_fields
    errors.extend(field.check(**kwargs))
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 893, in check
    errors = super(AutoField, self).check(**kwargs)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 208, in check
    errors.extend(self._check_backend_specific_checks(**kwargs))
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 311, in _check_backend_specific_checks
    return connections[db].validation.check_field(self, **kwargs)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/backends/mysql/validation.py", line 41, in check_field
    field_type = field.db_type(connection)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 629, in db_type
    return connection.data_types[self.get_internal_type()] % data
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 183, in data_types
    if self.features.supports_microsecond_precision:
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/backends/mysql/features.py", line 54, in supports_microsecond_precision
    return self.connection.mysql_version >= (5, 6, 4) and Database.version_info >= (1, 2, 5)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 367, in mysql_version
    with self.temporary_connection() as cursor:
  File "/usr/local/Cellar/python/2.7.12_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/backends/base/base.py", line 564, in temporary_connection
    cursor = self.cursor()
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/backends/base/base.py", line 231, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/backends/base/base.py", line 204, in _cursor
    self.ensure_connection()
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
    self.connect()
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
    self.connect()
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/backends/base/base.py", line 171, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 263, in get_new_connection
    conn = Database.connect(**conn_params)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/Users/scott/projects/CodingDojo/PythonDjango/djangoEnv/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (61)")

0 个答案:

没有答案