运行 python3 ./manage.py makemigrations 报错

来源:2-5 Mysql、Mongo、Redis安装

对于自己是一个挑战

2018-05-01

[root@localhost imoocc_online]# python3 ./manage.py makemigrations

Traceback (most recent call last):

  File "./manage.py", line 15, in <module>

    execute_from_command_line(sys.argv)

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line

    utility.execute()

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/core/management/__init__.py", line 330, in execute

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

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/core/management/base.py", line 390, in run_from_argv

    self.execute(*args, **cmd_options)

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/core/management/base.py", line 440, in execute

    self.check()

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/core/management/base.py", line 478, in check

    include_deployment_checks=include_deployment_checks,

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/core/checks/registry.py", line 72, in run_checks

    new_errors = check(app_configs=app_configs)

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/core/checks/model_checks.py", line 28, in check_all_models

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

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/models/base.py", line 1181, in check

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

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/models/base.py", line 1258, in _check_fields

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

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 934, in check

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

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 207, in check

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

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 306, in _check_backend_specific_checks

    return connection.validation.check_field(self, **kwargs)

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/backends/mysql/validation.py", line 18, in check_field

    field_type = field.db_type(connection)

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 614, in db_type

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

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/__init__.py", line 36, in __getattr__

    return getattr(connections[DEFAULT_DB_ALIAS], item)

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/utils/functional.py", line 60, in __get__

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

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 196, in data_types

    if self.features.supports_microsecond_precision:

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/utils/functional.py", line 60, in __get__

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

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/backends/mysql/features.py", line 52, in supports_microsecond_precision

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

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/utils/functional.py", line 60, in __get__

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

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 371, in mysql_version

    with self.temporary_connection():

  File "/usr/local/python3.6.2/lib/python3.6/contextlib.py", line 81, in __enter__

    return next(self.gen)

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/backends/base/base.py", line 462, in temporary_connection

    cursor = self.cursor()

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/backends/base/base.py", line 162, in cursor

    cursor = self.make_debug_cursor(self._cursor())

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/backends/base/base.py", line 135, in _cursor

    self.ensure_connection()

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection

    self.connect()

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/backends/base/base.py", line 119, in connect

    self.connection = self.get_new_connection(conn_params)

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 276, in get_new_connection

    conn = Database.connect(**conn_params)

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/MySQLdb/__init__.py", line 80, in Connect

    from MySQLdb.connections import Connection

  File "/usr/local/python3.6.2/lib/python3.6/site-packages/MySQLdb/connections.py", line 36

    raise errorclass, errorvalue


写回答

1回答

Jeson

2018-05-03

错误是不是不全?感觉是数据库连接不上导致,建议检查下settings.py的配置和数据库用户的授权,另外也要看下数据库服务状态是否成功,是否能正常访问到。

0
0

Python+Django+Ansible Playbook自动化运维项目实战

【课程升级3.6版本】大牛全面践行DevOps,运维与开发间高效协作

861 学习 · 326 问题

查看课程