Django错误(1146,Table 'operation.django_session' doesn't exist")

来源:互联网 发布:visio 2013 mac破解版 编辑:程序博客网 时间:2024/06/06 02:40

python3.5 django mysql pymysql MySQL


settings.py

# mysql 数据库import pymysqlpymysql.install_as_MySQLdb()

'default': {    'ENGINE': 'django.db.backends.mysql',    'NAME': mysql["name"],    'USER': mysql["user"],    'PASSWORD': mysql["pass"],    'HOST': mysql["host"],    'PORT': mysql["port"],}

表 5-1. 数据库引擎设置

设置数据库适配器postgresqlPostgreSQLpsycopg 版本 1.x, http://www.djangoproject.com/r/python-pgsql/1/.postgresql_psycopg2PostgreSQLpsycopg 版本 2.x, http://www.djangoproject.com/r/python-pgsql/.mysqlMySQLMySQLdb , http://www.djangoproject.com/r/python-mysql/.sqlite3SQLitePython 2.5+ 内建。 其他, pysqlite , http://www.djangoproject.com/r/python-sqlite/.ado_mssqlMicrosoft SQL Serveradodbapi 版本 2.0.1+, http://www.djangoproject.com/r/python-ado/.oracleOraclecx_Oracle , http://www.djangoproject.com/r/python-oracle/.

本次只看mysql,官方文档说django要使用mysql时,需要安装MySQL库,但是不幸的是我用了python3.5,然而MySQL不支持python3.5;在python3.5中可以使用pymysql,但又有一个不幸,就是pymysql不支持django,下来主要说说怎么解决: 
可以在setting.py同目录下的__init__.py中添加如下命令或在setting文件添加

import pymysql
pymysql.install_as_MySQLdb()


然后重新同步数据库,并新建用户名密码:
# python manage.py makemigrations
# python manage.py migrate
# python manage.py createsuperuser

如果不做最后这一步,当运行服务器之后,打开浏览器http://127.0.0.1:8000 就会出现这样一个错误(1146,Table operation.django_session’ doesn’t exist”)

阅读全文
1 0