Get the App
SLTechnology News&Howtos  ›  Database  › 

Database configuration of Django in Python Framework

Shulou Source: shulou.com Published: 2022-06-01 06:13:03 10月01日 Update

Ready to start the python environment, use the django framework whose default database is sqlite3, and use mysql to store data instead

There was a problem executing migrate (see error at the end):

Unhandled exception in thread started by

Traceback (most recent call last):

File "C:\ Python36\ lib\ site-packages\ django\ db\ backends\ base\ base.py", line 213

, in ensure_connection

Self.connect ()

File "C:\ Python36\ lib\ site-packages\ django\ db\ backends\ base\ base.py", line 189

, in connect

Self.connection = self.get_new_connection (conn_params)

File "C:\ Python36\ lib\ site-packages\ django\ db\ backends\ mysql\ base.py", line 27

4, in get_new_connection

Conn = Database.connect (* * conn_params)

File "C:\ Python36\ lib\ site-packages\ MySQLdb\ _ init__.py", line 86, in Connect

Return Connection (* args, * * kwargs)

File "C:\ Python36\ lib\ site-packages\ MySQLdb\ connections.py", line 204, in _ _ in

It__

Super (Connection, self). _ _ init__ (* args, * kwargs2)

_ mysql_exceptions.OperationalError: (1045, "Access denied for user 'ODBC'@'local

Host' (using password: YES) ")

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

Traceback (most recent call last):

File "C:\ Python36\ lib\ site-packages\ django\ utils\ autoreload.py", line 227, in

Wrapper

Fn (* args, * * kwargs)

File "C:\ Python36\ lib\ site-packages\ django\ core\ management\ commands\ runserver.

Py ", line 125, in inner_run

Self.check (display_num_errors=True)

File "C:\ Python36\ lib\ site-packages\ django\ core\ management\ base.py", line 359

In check

Include_deployment_checks=include_deployment_checks

File "C:\ Python36\ lib\ site-packages\ django\ core\ management\ base.py", line 346

In _ run_checks

Return checks.run_checks (* * kwargs)

File "C:\ Python36\ lib\ site-packages\ django\ core\ checks\ registry.py", line 81

In run_checks

New_errors = check (app_configs=app_configs)

File "C:\ Python36\ lib\ site-packages\ django\ core\ checks\ model_checks.py", line

30, in check_all_models

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

File "C:\ Python36\ lib\ site-packages\ django\ db\ models\ base.py", line 1282, in c

Heck

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

File "C:\ Python36\ lib\ site-packages\ django\ db\ models\ base.py", line 1357, in _

Check_fields

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

File "C:\ Python36\ lib\ site-packages\ django\ db\ models\ fields\ _ init__.py", line

909, in check

Errors = super (AutoField, self). Check (* kwargs)

File "C:\ Python36\ lib\ site-packages\ django\ db\ models\ fields\ _ init__.py", line

219, in check

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

File "C:\ Python36\ 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:\ Python36\ lib\ site-packages\ django\ db\ backends\ mysql\ validation.py", l

Ine 49, in check_field

Field_type = field.db_type (self.connection)

File "C:\ Python36\ lib\ site-packages\ django\ db\ models\ fields\ _ init__.py", line

640, in db_type

Return connection.data_ types [self.get _ internal_type ()]% data

File "C:\ Python36\ lib\ site-packages\ django\ utils\ functional.py", line 35, in _

_ get__

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

File "C:\ Python36\ lib\ site-packages\ django\ db\ backends\ mysql\ base.py", line 17

4, in data_types

If self.features.supports_microsecond_precision:

File "C:\ Python36\ lib\ site-packages\ django\ utils\ functional.py", line 35, in _

_ get__

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

File "C:\ Python36\ lib\ site-packages\ django\ db\ backends\ mysql\ features.py", lin

E 53, in supports_microsecond_precision

Return self.connection.mysql_version > = (5,6,4) and Database.version_info

> = (1,2,5)

File "C:\ Python36\ lib\ site-packages\ django\ utils\ functional.py", line 35, in _

_ get__

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

File "C:\ Python36\ lib\ site-packages\ django\ db\ backends\ mysql\ base.py", line 38

5, in mysql_version

With self.temporary_connection () as cursor:

File "C:\ Python36\ lib\ contextlib.py", line 82, in _ _ enter__

Return next (self.gen)

File "C:\ Python36\ lib\ site-packages\ django\ db\ backends\ base\ base.py", line 591

, in temporary_connection

Cursor = self.cursor ()

File "C:\ Python36\ lib\ site-packages\ django\ db\ backends\ base\ base.py", line 254

, in cursor

Return self._cursor ()

File "C:\ Python36\ lib\ site-packages\ django\ db\ backends\ base\ base.py", line 229

, in _ cursor

Self.ensure_connection ()

File "C:\ Python36\ lib\ site-packages\ django\ db\ backends\ base\ base.py", line 213

, in ensure_connection

Self.connect ()

File "C:\ Python36\ lib\ site-packages\ django\ db\ utils.py", line 94, in _ _ exit__

Six.reraise (dj_exc_type, dj_exc_value, traceback)

File "C:\ Python36\ lib\ site-packages\ django\ utils\ six.py", line 685, in reraise

Raise value.with_traceback (tb)

File "C:\ Python36\ lib\ site-packages\ django\ db\ backends\ base\ base.py", line 213

, in ensure_connection

Self.connect ()

File "C:\ Python36\ lib\ site-packages\ django\ db\ backends\ base\ base.py", line 189

, in connect

Self.connection = self.get_new_connection (conn_params)

File "C:\ Python36\ lib\ site-packages\ django\ db\ backends\ mysql\ base.py", line 27

4, in get_new_connection

Conn = Database.connect (* * conn_params)

File "C:\ Python36\ lib\ site-packages\ MySQLdb\ _ init__.py", line 86, in Connect

Return Connection (* args, * * kwargs)

File "C:\ Python36\ lib\ site-packages\ MySQLdb\ connections.py", line 204, in _ _ in

It__

Super (Connection, self). _ _ init__ (* args, * kwargs2)

Django.db.utils.OperationalError: (1045, "Access denied for user 'ODBC'@'localho

St' (using password: YES) ")

It's strange why the user I configured is admin_py. How can I display 'ODBC'@'localhost'?'?

Some people say that it is the account password error, which seems to be related to the account password error through the error report, but it is OK to log in MySQL manually!

After tossing about for a while, take a closer look at the official documentation configuration:

DATABASES = {'default': {' ENGINE': 'django.db.backends.postgresql',' NAME': 'mydatabase',' USER': 'mydatabaseuser',' PASSWORD': 'mypassword',' HOST': '127.0.0.1,' PORT': '5432,}}

My own configuration:

DATABASES = {'default': {' ENGINE': 'django.db.backends.mysql',' HOST': '127.0.0.1,' PORT': 3306, 'NAME':' platform_admin_py', 'USERNAME':' admin_py', 'PASSWORD':' admin',}}

Did you find out? The KEY of the user name is wrong! I admit that I read other people's configuration on the Internet. I'm lazy. That's the price.

Tags: Configuration error data password user account database framework problem wrong cost official that is manual document time end environment user name yes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Microsoft OPPO Reno Xiaomi Shulou Information