这些错误是啥意思? django中的mysql

Posted

技术标签:

【中文标题】这些错误是啥意思? django中的mysql【英文标题】:What do these errors mean ? mysql in django这些错误是什么意思? django中的mysql 【发布时间】:2017-07-26 05:12:16 【问题描述】:

我正在尝试运行一个程序,作为示例,它就像一个购物网站,它使用 mysql 数据库而不是 Django 中提供的原始数据库!我只是想看看是否有人理解这些错误的含义?任何信息,将不胜感激!我会提供网页的代码,但有很多内容不适合!

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
    self.check(display_num_errors=True)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 374, in check
    include_deployment_checks=include_deployment_checks,
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 361, in _run_checks
    return checks.run_checks(**kwargs)
  File "/Library/Python/2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/Library/Python/2.7/site-packages/django/core/checks/model_checks.py", line 30, in check_all_models
    errors.extend(model.check(**kwargs))
  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 1266, in check
    errors.extend(cls._check_fields(**kwargs))
  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 1337, in _check_fields
    errors.extend(field.check(**kwargs))
  File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 893, in check
    errors = super(AutoField, self).check(**kwargs)
  File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 208, in check
    errors.extend(self._check_backend_specific_checks(**kwargs))
  File "/Library/Python/2.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 "/Library/Python/2.7/site-packages/django/db/backends/mysql/validation.py", line 41, in check_field
    field_type = field.db_type(connection)
  File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 629, in db_type
    return connection.data_types[self.get_internal_type()] % data
  File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 183, in data_types
    if self.features.supports_microsecond_precision:
  File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Library/Python/2.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 "/Library/Python/2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 367, in mysql_version
    with self.temporary_connection() as cursor:
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/Library/Python/2.7/site-packages/django/db/backends/base/base.py", line 564, in temporary_connection
    cursor = self.cursor()
  File "/Library/Python/2.7/site-packages/django/db/backends/base/base.py", line 231, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/Library/Python/2.7/site-packages/django/db/backends/base/base.py", line 204, in _cursor
    self.ensure_connection()
  File "/Library/Python/2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
    self.connect()
  File "/Library/Python/2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Library/Python/2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
    self.connect()
  File "/Library/Python/2.7/site-packages/django/db/backends/base/base.py", line 171, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 263, in get_new_connection
    conn = Database.connect(**conn_params)
  File "/Library/Python/2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1045, "Access denied for user 'abc'@'localhost' (using password: YES)")

【问题讨论】:

阅读最后一行 您在设置中配置的 MySQL 用户不允许访问您的 MySQL 数据库。这是在最后一行以纯文本形式编写的。 【参考方案1】:

这意味着您用于连接 MySQL 数据库的连接字符串(在 Django 中为数据库凭据)是错误的。在 settings.py 中检查您的用户名、密码、主机、端口、数据库名称,并确保您的数据库正在接受来自您的服务器的连接。

【讨论】:

【参考方案2】:

检查 settings.py

 DATABASES = 
     'default': 
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'djangocrud',
        'USER':'root',
        'PASSWORD':'pass$123',
        'HOST':'127.0.0.1',
        'PORT':'3306',
    

也许你需要这个 https://docs.djangoproject.com/en/1.10/ref/settings/#std:setting-DATABASES

【讨论】:

以上是关于这些错误是啥意思? django中的mysql的主要内容,如果未能解决你的问题,请参考以下文章

这些错误是啥意思 getReadModeConfig, getReadModeRender, getReadModeExtract

错误信息“com.mysql.cj.exceptions.WrongArgumentException:数据库 URL 不能为空”是啥意思。意思是?

刚学使用MYSQL,登陆时提示错误信息1067,哪位大侠帮解答下是啥意思,谢谢

Dask 中的 KilledWorker 异常是啥意思?

这些'未定义的对 __glut*WithExit' OpenGL 链接器错误的引用是啥意思? [复制]

MySQL、JSON、Python、Django - 完全错误