请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

manage.py makemigrations 报错,请老师 协助查下原因

root@ubuntu:/home/rlg/imoocc_online# /opt/python2.7/bin/python ./manage.py makemigrations
Traceback (most recent call last):
  File "./manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/python2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/opt/python2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/python2.7/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/python2.7/lib/python2.7/site-packages/django/core/management/base.py", line 440, in execute
    self.check()
  File "/opt/python2.7/lib/python2.7/site-packages/django/core/management/base.py", line 478, in check
    include_deployment_checks=include_deployment_checks,
  File "/opt/python2.7/lib/python2.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/opt/python2.7/lib/python2.7/site-packages/django/core/checks/model_checks.py", line 28, in check_all_models
    errors.extend(model.check(**kwargs))
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/models/base.py", line 1181, in check
    errors.extend(cls._check_fields(**kwargs))
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/models/base.py", line 1258, in _check_fields
    errors.extend(field.check(**kwargs))
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 934, in check
    errors = super(AutoField, self).check(**kwargs)
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 207, in check
    errors.extend(self._check_backend_specific_checks(**kwargs))
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 306, in _check_backend_specific_checks
    return connection.validation.check_field(self, **kwargs)
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/backends/mysql/validation.py", line 18, in check_field
    field_type = field.db_type(connection)
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 614, in db_type
    return connection.data_types[self.get_internal_type()] % data
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/__init__.py", line 36, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/opt/python2.7/lib/python2.7/site-packages/django/utils/functional.py", line 60, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 196, in data_types
    if self.features.supports_microsecond_precision:
  File "/opt/python2.7/lib/python2.7/site-packages/django/utils/functional.py", line 60, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/opt/python2.7/lib/python2.7/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 "/opt/python2.7/lib/python2.7/site-packages/django/utils/functional.py", line 60, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 371, in mysql_version
    with self.temporary_connection():
  File "/opt/python2.7/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/backends/base/base.py", line 462, in temporary_connection
    cursor = self.cursor()
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/backends/base/base.py", line 162, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/backends/base/base.py", line 135, in _cursor
    self.ensure_connection()
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/backends/base/base.py", line 119, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/opt/python2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 276, in get_new_connection
    conn = Database.connect(**conn_params)
  File "/opt/python2.7/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/opt/python2.7/lib/python2.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 'imoocc'@'localhost' (using password: YES)")

正在回答

1回答

错误是没有建立mysql的权限,这个课程中有介绍,首先:

1、看看 settings中的配置,如下:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'imoocc',
        'USER': 'imoocc',
        'PASSWORD': 'imoocccom',
        'HOST': '127.0.0.1',
        'PORT': '',
        'OPTIONS': {},
        'init_command': 'SET storage_engine=INNODB,'
                        'SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED, autocommit=1, names "utf8";',
    }
}


2、用root用户登陆mysql

mysql -uroot -p

先创建imoocc库,如下:

mysql> create database imoocc

登陆后建立imoocc用户权限,如下:

mysql> grant all on imoocc.* to imoocc@'%' identified by 'imoocccom';

Query OK, 0 rows affected (0.00 sec)

mysql> grant all on imoocc.* to imoocc@'localhost' identified by 'imoocccom';

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;                                                   

Query OK, 0 rows affected (0.00 sec)


3、测试

用mysql命令测试,如下:

mysql -uimoocc -p'imoocccom' -h mysql服务的IP地址


0 回复 有任何疑惑可以回复我~
  • 提问者 sunshinebao #1
    非常感谢!
    回复 有任何疑惑可以回复我~ 2018-05-06 22:00:50
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信