标签:message migrate 必须 collate 建表 ons enc username import
由于Django自带的orm是data_first类型的ORM,使用前必须先创建数据库
create database db default character set utf8 collate utf8_general_ci;
DATABASES = { ‘default‘: { ‘ENGINE‘: ‘django.db.backends.mysql‘, ‘NAME‘:‘dbname‘, ‘USER‘: ‘xxx‘, ‘PASSWORD‘: ‘xxx‘, ‘HOST‘: ‘localhost‘, ‘PORT‘: ‘3306‘, } }
import pymysql
pymysql.install_as_MySQLdb()
此时运行程序,如果报错:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
解决方法:
1: 将django降到2.1.4版本(使用Django2.2版本会出现此问题,亲测可用)
2:进入到python安装目录下:。。。/site-packages/django/db/backends/mysql的base.py文件,注释掉如下部分(35-36行):
if version < (1, 3, 3): raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)
此时仍会会报错,报错信息如下:AttributeError: ‘str’ object has no attribute ‘decode
找到operations.py文件(146行),将decode改为encode(146行):
if query is not None:
query = query.decode(errors=‘replace‘)
return query
改为
if query is not None:
query = query.encode(errors=‘replace‘)
return query
python manage.py startapp app01
class UserInfo(models.Model): nid = models.BigAutoField(primary_key=True) username = models.CharField(max_length=32) password = models.CharField(max_length=64)
INSTALLED_APPS = [ ‘django.contrib.admin‘, ‘django.contrib.auth‘, ‘django.contrib.contenttypes‘, ‘django.contrib.sessions‘, ‘django.contrib.messages‘, ‘django.contrib.staticfiles‘, ‘app01‘, #末尾添加 ]
python manage.py makemigrations
python manage.py migrate
标签:message migrate 必须 collate 建表 ons enc username import
原文地址:https://www.cnblogs.com/cky-2907183182/p/11329627.html