标签:error int errors 解决方法 setting mic bug 一个 ble
给Django配置mysql数据库
现在settings中将DATABASES重新设置
DATABASES = {
‘default‘: {
‘ENGINE‘: ‘django.db.backends.mysql‘,
‘NAME‘: "databasename",
‘PASSWORD‘: "password",
‘USER‘:"rusername",
‘HOST‘: "localhost",
‘PORT‘: 3306,
‘OPTIONS‘: { "init_command": "SET default_storage_engine=‘INNODB‘"
} #设定mysql数据库的初始引擎,也可以加入其他字段,如 chaeset等
}
}
执行python manage.py makemigrations时,报错:
‘Did you install mysqlclient or MySQL-python?‘ % e
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named ‘MySQLdb‘.
Did you install mysqlclient or MySQL-python?
经过上网搜索得知,MySQLdb并不支持Python3.5,因此只能找别的类库代替。
解决方法:
使用pymysql代替MySQLdb,因为两者的用法完全一致,步骤:
1. PIP install pymysql
2. 执行成功后,打开__init__.py,添加如下:
import pymysql
pymysql.install_as_MySQLdb()
3. 重新执行python manage.py makemigrations,成功。
实际上按照给出的提示是要安装mysqlclient的,但是在pip下安装会报错,要去下载执行文件,我比较懒,就换一个方式吧.后面如果出错,再来更新,嘿嘿嘿.
接着执行python3 mange.py migrate,报错如下:
WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection ‘default‘
HINT: MySQL‘s Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it.
说明当前使用的mysql数据库不是严格模式.严格模式下:
1.不支持对not null字段插入null值
2.不支持对自增长字段插入""值
3.不支持text字段有默认值
需要进行数据库的改动,以防止bug出现.
在settings中,数据库设置下面插入:
DATABASES[‘default‘][‘OPTIONS‘][‘init_command‘] = "SET sql_mode=‘STRICT_TRANS_TABLES‘"
标签:error int errors 解决方法 setting mic bug 一个 ble
原文地址:https://www.cnblogs.com/xiujin/p/9693794.html