makemigrations messages报错目标计算机积极拒绝

来源:3-3 django orm介绍与model设计

苏家小萝卜

2017-07-05

"C:\Program Files\JetBrains\PyCharm 2017.1.4\bin\runnerw.exe" C:\Users\娜娜\Envs\testvir2\Scripts\python.exe "C:\Program Files\JetBrains\PyCharm 2017.1.4\helpers\pycharm\django_manage.py" makemigrations messages C:/Users/娜娜/PycharmProjects/djangotest

Traceback (most recent call last):

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\pymysql\connections.py", line 916, in connect

    **kwargs)

  File "c:\program files\python36\Lib\socket.py", line 722, in create_connection

    raise err

  File "c:\program files\python36\Lib\socket.py", line 713, in create_connection

    sock.connect(sa)

ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\backends\base\base.py", line 213, in ensure_connection

    self.connect()

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\backends\base\base.py", line 189, in connect

    self.connection = self.get_new_connection(conn_params)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\backends\mysql\base.py", line 274, in get_new_connection

    conn = Database.connect(**conn_params)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\pymysql\__init__.py", line 90, in Connect

    return Connection(*args, **kwargs)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\pymysql\connections.py", line 706, in __init__

    self.connect()

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\pymysql\connections.py", line 963, in connect

    raise exc

pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' ([WinError 10061] 由于目标计算机积极拒绝,无法连接。)")


The above exception was the direct cause of the following exception:


Traceback (most recent call last):

  File "C:\Program Files\JetBrains\PyCharm 2017.1.4\helpers\pycharm\django_manage.py", line 43, in <module>

    run_module(manage_file, None, '__main__', True)

  File "c:\program files\python36\Lib\runpy.py", line 205, in run_module

    return _run_module_code(code, init_globals, run_name, mod_spec)

  File "c:\program files\python36\Lib\runpy.py", line 96, in _run_module_code

    mod_name, mod_spec, pkg_name, script_name)

  File "c:\program files\python36\Lib\runpy.py", line 85, in _run_code

    exec(code, run_globals)

  File "C:/Users/娜娜/PycharmProjects/djangotest\manage.py", line 24, in <module>

    execute_from_command_line(sys.argv)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line

    utility.execute()

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\core\management\__init__.py", line 355, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv

    self.execute(*args, **cmd_options)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\core\management\base.py", line 327, in execute

    self.check()

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\core\management\base.py", line 359, in check

    include_deployment_checks=include_deployment_checks,

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\core\management\base.py", line 346, in _run_checks

    return checks.run_checks(**kwargs)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks

    new_errors = check(app_configs=app_configs)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\core\checks\model_checks.py", line 30, in check_all_models

    errors.extend(model.check(**kwargs))

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\models\base.py", line 1282, in check

    errors.extend(cls._check_fields(**kwargs))

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\models\base.py", line 1357, in _check_fields

    errors.extend(field.check(**kwargs))

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\models\fields\__init__.py", line 913, in check

    errors = super(AutoField, self).check(**kwargs)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\models\fields\__init__.py", line 219, in check

    errors.extend(self._check_backend_specific_checks(**kwargs))

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\models\fields\__init__.py", line 322, in _check_backend_specific_checks

    return connections[db].validation.check_field(self, **kwargs)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\backends\mysql\validation.py", line 49, in check_field

    field_type = field.db_type(self.connection)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\models\fields\__init__.py", line 644, in db_type

    return connection.data_types[self.get_internal_type()] % data

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\utils\functional.py", line 35, in __get__

    res = instance.__dict__[self.name] = self.func(instance)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\backends\mysql\base.py", line 174, in data_types

    if self.features.supports_microsecond_precision:

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\utils\functional.py", line 35, in __get__

    res = instance.__dict__[self.name] = self.func(instance)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\backends\mysql\features.py", line 53, in supports_microsecond_precision

    return self.connection.mysql_version >= (5, 6, 4) and Database.version_info >= (1, 2, 5)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\utils\functional.py", line 35, in __get__

    res = instance.__dict__[self.name] = self.func(instance)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\backends\mysql\base.py", line 385, in mysql_version

    with self.temporary_connection() as cursor:

  File "c:\program files\python36\Lib\contextlib.py", line 82, in __enter__

    return next(self.gen)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\backends\base\base.py", line 591, in temporary_connection

    cursor = self.cursor()

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\backends\base\base.py", line 254, in cursor

    return self._cursor()

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\backends\base\base.py", line 229, in _cursor

    self.ensure_connection()

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\backends\base\base.py", line 213, in ensure_connection

    self.connect()

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\utils.py", line 94, in __exit__

    six.reraise(dj_exc_type, dj_exc_value, traceback)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\utils\six.py", line 685, in reraise

    raise value.with_traceback(tb)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\backends\base\base.py", line 213, in ensure_connection

    self.connect()

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\backends\base\base.py", line 189, in connect

    self.connection = self.get_new_connection(conn_params)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\django\db\backends\mysql\base.py", line 274, in get_new_connection

    conn = Database.connect(**conn_params)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\pymysql\__init__.py", line 90, in Connect

    return Connection(*args, **kwargs)

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\pymysql\connections.py", line 706, in __init__

    self.connect()

  File "C:\Users\娜娜\Envs\testvir2\lib\site-packages\pymysql\connections.py", line 963, in connect

    raise exc

django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' ([WinError 10061] 由于目标计算机积极拒绝,无法连接。)")

尝试解决:

  1. 把系统hosts文件的127.0.0.1端口放开

  2. setting.py里设置如下:

  3. DATABASES = {
       'default': {
           'ENGINE': 'django.db.backends.mysql',
           'NAME': "testdjango",
           'USER': "root",
           'PASSWORD': "xxx保密",
           'HOST': "127.0.0.1",
       }
    }

写回答

1回答

bobby

2017-07-06

你本地计算机是否mysql没有启动?

0
2
苏家小萝卜
老师,我昨天后来发现确实是没有启动,因为平时都是自动启动的,没去注意
2017-07-06
共2条回复

Python3.6+django+xadmin,打造在线教育平台

【毕设】Python 2.7到3.6 完美适配,Django升级2.0

3677 学习 · 4038 问题

查看课程