Django 迁移数据库可能出现的错误

1.输入:python3 manage.py makemigrations

出现的错误:ModuleNotFoundError: No module named 'MySQLdb'

解决方案:要导入pymysql模块

那么具体在哪里导入呢?如下图:
	在Diango_ORM_Muti文件下的 __init__.py文件里
  	写下面代码:
   		import pymysql
   		pymysql.install_as_MySQLdb()

在这里插入图片描述

2.重新输入:python3 manage.py makemigrations

出现错误:

File "~/mysql/base.py", line 36, in <module>
     raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

解决方案

在base.py文件中,注释点下面的代码

   # if version < (1, 3, 13):
   #     raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

3.重新输入:python3 manage.py makemigrations
出现错误:

   File ".../mysql/operations.py", line 146, in last_executed_query
          query = query.decode(errors='replace')
  AttributeError: 'str' object has no attribute 'decode'

解决方案

def last_executed_query(self, cursor, sql, params):
    query = getattr(cursor, '_executed', None)
    if query is not None:
        query = query.decode(errors='replace') 修改代码:decode修改成encode
   		return query

4.重新输入 :python3 manage.py makemigrations

Migrations for 'app01':
  app01/migrations/0001_initial.py
   - Create model Author
   - Create model Publish
   - Create model Book

5.输入 :python3 manage.py migrate

Operations to perform:
  Apply all migrations: admin, app01, auth, contenttypes, sessions
Running migrations:
  .......
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值