日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

本文介紹了Django遷移錯誤'TypeError:Sequence Item 1:需要一個類似字節的對象,但在MySQL-Connector-Python Cursor_cent.py文件上找到了字符串的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我使用MySQL-Connector來處理Django項目中的MySQL請求。問題是,我正在使用django-admin startproject項目設置一個簡單的項目。當我嘗試執行簡單的管理時,這是我的輸出。

$ python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
aqui <mysql.connector.cursor_cext._ParamSubstitutor object at 0x7f408ae1ec10> b'SELECT engine FROM information_schema.tables WHERE table_name = %s'
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 244, in handle
    post_migrate_state = executor.migrate(
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 91, in migrate
    self.recorder.ensure_schema()
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 68, in ensure_schema
    editor.create_model(self.Migration)
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 348, in create_model
    self.deferred_sql.extend(self._model_indexes_sql(model))
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 1087, in _model_indexes_sql
    output.extend(self._field_indexes_sql(model, field))
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 1106, in _field_indexes_sql
    if self._field_should_be_indexed(model, field):
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/db/backends/mysql/schema.py", line 111, in _field_should_be_indexed
    storage = self.connection.introspection.get_storage_engine(
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/mysql/connector/django/introspection.py", line 270, in get_storage_engine
    cursor.execute(
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 98, in execute
    return super().execute(sql, params)
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/mysql/connector/django/base.py", line 149, in execute
    return self.cursor.execute(query, new_args)
  File "/home/thejhoule/anon/anonproj/end/venv/lib/python3.8/site-packages/mysql/connector/cursor_cext.py", line 265, in execute
    stmt = RE_PY_PARAM.sub(psub, stmt)
TypeError: sequence item 1: expected a bytes-like object, str found

我已將設置正確配置為

DATABASES = {
    'default': {
        'NAME': 'dbname',
        'ENGINE': 'mysql.connector.django',
        'USER': 'XXXXX',
        'PASSWORD': 'XXXXX',
        'OPTIONS': {
            'autocommit': True
        }
    }
}

和通過MySQL外殼正確創建的數據庫名。我還注意到,當我運行了兩次之后,在這個數據庫上創建了兩個表(第一次運行時,出現了上述錯誤,但沒有在我的數據庫上創建表)。

我嘗試處理stmt = RE_PY_PARAM.sub(psub, stmt)附近的代碼,甚至嘗試輸入stmt.decode('utf-8')。然后,它會在同一點引發不同的錯誤

tmt = RE_PY_PARAM.sub(psub, stmt.decode('utf-8'))
TypeError: cannot use a bytes pattern on a string-like object

我使用的是Ubuntu 20.04,所有這些操作都是在一個pythonvenv中完成的,并通過pip安裝了Django和mySQL連接器-python。

推薦答案

這似乎是mysql-connector-python==8.0.27的錯誤,可以通過回滾一個版本來避免:

pip install mysql-connector-python<=8.0.26

這篇關于Django遷移錯誤&#39;TypeError:Sequence Item 1:需要一個類似字節的對象,但在MySQL-Connector-Python Cursor_cent.py文件上找到了字符串的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,

分享到:
標簽:database-migration django django-migrations errorDjangoMigrationError'T
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定