Django使用mysql数据库坑:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13

我在迁移数据库的时候,从默认的sqlite3 迁移到 mysql 中的过程和一些坑

报错: django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3

步骤

  1. 配置 setting.py
  2. 安装 mysqlclient
  3. 迁移数据

注意:不要用 PyMySQL0.9.3

这是一个坑 安装 自带的 mysqlclient 就好了

  • 具体配置如下:
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',  # 使用的数据库驱动
        'NAME': 'test',
        'USER': 'root',
        'PASSWORD': '123456',
        'HOST': '127.0.0.1',
        'PORT': '3306',
    }
}
  • 安装
    pip install mysqlclient

  • 迁移数据

 python manage.py makemigrations
  python manage.py migrate 

注意:不要听其他教程安装什么 PyMySQL 0.9.3 什么 init文件 import 导入 都不用 ! 就这样就可以了

ps:附环境

python --3.7
pycharm -- 2019.1.1
django -- 2.2.5
发布了130 篇原创文章 · 获赞 91 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/Chad97/article/details/102525249