真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Python框架之Django的數(shù)據(jù)庫配置問題

準備開始python的環(huán)境,用django框架其默認的數(shù)據(jù)庫是sqlite3 ,要改用MySQL來存儲數(shù)據(jù)

創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),紅旗企業(yè)網(wǎng)站建設(shè),紅旗品牌網(wǎng)站建設(shè),網(wǎng)站定制,紅旗網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,紅旗網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。

在執(zhí)行migrate的時候出現(xiàn)問題(錯誤見末尾):


Unhandled exception in thread started by .wrapper

 at 0x031BD6F0>

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)")

這里很奇怪為什么我配置的用戶是 admin_py 怎么會顯示 ‘ODBC’@‘localhost’?

有人說是賬號密碼錯誤,通過報錯看來的和賬號密碼錯誤相關(guān),但是手工去登陸mysql是OK的??!

折騰了一會兒,仔細看官方文檔配置:

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

我自己的配置:

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

發(fā)現(xiàn)了沒有?用戶名的的那個KEY不對! 我承認我這是從網(wǎng)上看別人的配置寫的,偷懶了,這就是代價


當前標題:Python框架之Django的數(shù)據(jù)庫配置問題
標題來源:http://weahome.cn/article/ggdpeh.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部