错误1
python3 与 Django 连接数据库:Error loading MySQLdb module: No module named ‘MySQLdb’
解决方法:在 init.py 文件中添加以下代码即可。
import pymysql
pymysql.install_as_MySQLdb()
错误2
在执行python manage.py migrate报一下错误
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table ((1064, “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near ‘(6) NOT NULL)’ at line 1”))
请检测你的环境版本,Django2.1只支持mysql5.6以上的版本!只需要升级你的mysql版本或降django到2.0即可。
错误3
解决Django admin 插入中文时候出现乱码问题
ALTER TABLE blog_blogpost MODIFY COLUMN body VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
// 需要注意的是 blog_blogpost 这个表示的是 表名 body 这个是列名 要根据自己项目所需要的 表和列进行修改
错误4
Django分页出现UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered ob
将
messeges = MessegeModel.objects.all()
变为
messeges = MessegeModel.objects.get_queryset().order_by('id')
错误5
RuntimeWarning: DateTimeField Message.publish received a naive datetime (2018-12-12 16:29:58) while time zone support is active.
RuntimeWarning)
settings.py中的USE_TZ= True的原因,把True改成False即可。