python3.5 Django MySQL pymysql mysql
Database_engine = "
database_name = "
Database_user = "
Database_password = "
Database_host = "
Database_port = "
What the above fields mean, this is not explained here.
The main thing to look at is database_engine how to define different databases, according to the official documentation, as shown in the following table: table 5-1. Database Engine Settings
setting |
database |
adapter |
p Ostgresql |
PostgreSQL |
PSYCOPG version 1.x, http://www.djangoproject.com/r/python-pgsql/1/. |
postgresql_psycopg2 |
PostgreSQL |
PSYCOPG version 2.x, http://www.djangoproject.co m/r/python-pgsql/. |
mysql |
mysql |
mysqldb, http://www.djangoproject.com/r/python-mysql/. |
sqlite3 |
SQLite |
Python 2.5+ built. Other, Pysqlite, http://www.djangoproject.com/r/python-sqlite/. |
ado_mssql |
Microsoft SQL Server |
adodbapi version 2.0.1+, HTTP://WWW.DJANGOPROJEC t.com/r/python-ado/. |
Oracle |
Oracle |
cx_oracle, http://www.djangoproject.com/r/python-oracle/. |
Other databases are not discussed here, first look at MySQL, the official document said Django to use MySQL, need to install the MySQL library, But unfortunately I used the python3.5, but MySQL does not support python3.5, in the python3.5 can use Pymysql, but another unfortunate, is that Pymysql does not support Django, down the main talk about how to solve:
You can add the following command to the __init__.py in the setting.py directory:
Import Pymysql
pymysql.install_as_mysqldb ()
Then resynchronize the database and create a new username password:
$python manage.py makemigrations
$python manage.py migrate
$python manage.py createsuperuser
If you do not do this last step, when you run the server, the error occurs when you open the browser http://127.0.0.1:8000 (1146,table ' blog.django_session ' doesn ' t exist ")