AttributeError:在Django中迁移时,模块'MySQLdb.constants.FIELD_TYPE'没有属性'JSON' [英] AttributeError: module 'MySQLdb.constants.FIELD_TYPE' has no attribute 'JSON' while migrating in Django

查看:185
本文介绍了AttributeError:在Django中迁移时,模块'MySQLdb.constants.FIELD_TYPE'没有属性'JSON'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道以什么方式解决此错误.有什么提示吗?我有简单的Django项目,尝试执行python3 manage.py migration时收到此错误.这与应用程序中的任何编程错误有关,还是可能与mysql的安装及其软件包的完整性有关的任何错误?也许manage.py文件中有任何错误?还是在不兼容的Django和mysql版本中是这种情况?

I do not know in what way solve this error. Any hints? I have simple Django projects and receive this error when try to do python3 manage.py migrate. This is related to any programming error in app or this is possible there is any error related to installation of mysql and completeness of its packages? Maybe there is any error in manage.py file? Or maybe this is case in not compatible version of Django and mysql?

Traceback (most recent call last):
 File "manage.py", line 23, in <module>
execute_from_command_line(sys.argv)
File "/home/anna/.local/lib/python3.7/site-packages/django/core/management/__init__.py",      
line 401, in execute_from_command_line
utility.execute()
File "/home/anna/.local/lib/python3.7/site-packages/django/core/management/__init__.py",    
line 377, in execute
django.setup()
File "/home/anna/.local/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/anna/.local/lib/python3.7/site-packages/django/apps/registry.py", line 114, in     
populate
app_config.import_models()
File "/home/anna/.local/lib/python3.7/site-packages/django/apps/config.py", line 211, in   
import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/anna/.local/lib/python3.7/site-packages/django/contrib/auth/models.py", line 2,   
in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/home/anna/.local/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 
48, in <module>
class AbstractBaseUser(models.Model):
File "/home/anna/.local/lib/python3.7/site-packages/django/db/models/base.py", line 122, in 
__new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/home/anna/.local/lib/python3.7/site-packages/django/db/models/base.py", line 326, in 
add_to_class
value.contribute_to_class(cls, name)
File "/home/anna/.local/lib/python3.7/site-packages/django/db/models/options.py", line 206, 
in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/anna/.local/lib/python3.7/site-packages/django/db/__init__.py", line 28, in 
__getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/anna/.local/lib/python3.7/site-packages/django/db/utils.py", line 214, in 
__getitem__
backend = load_backend(db['ENGINE'])
File "/home/anna/.local/lib/python3.7/site-packages/django/db/utils.py", line 111, in 
load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/anna/.local/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 
29, in <module>
from .introspection import DatabaseIntrospection            # isort:skip
File "/home/anna/.local/lib/python3.7/site-
packages/django/db/backends/mysql/introspection.py", line 16, in <module>
class DatabaseIntrospection(BaseDatabaseIntrospection):
File "/home/anna/.local/lib/python3.7/site-   
packages/django/db/backends/mysql/introspection.py", line 27, in DatabaseIntrospection
FIELD_TYPE.JSON: 'JSONField',
AttributeError: module 'MySQLdb.constants.FIELD_TYPE' has no attribute 'JSON'

推荐答案

pip install mysqlclient==2.0.1

您需要更新mysqlclient,当前版本是2.0.1,它可以解决此缺失的定义.

You need to update mysqlclient, version 2.0.1 is the current version and it solves this missing definition.

这篇关于AttributeError:在Django中迁移时,模块'MySQLdb.constants.FIELD_TYPE'没有属性'JSON'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆