Django configuration parameter settings for MySQL
DATABASES = { 'default': { 'ENGINE':'Django.db.backends.mysql', 'NAME':'Djangodb', 'USER':'Root', 'PASSWORD':'123456', 'HOST':'127.0.0.1', 'PORT':'3306', }}
After the parameters are set, we need to test whether the settings are successful. Enter your own project directory, execute the Python manage.py shell, and enter the following command:
from Import connectioncursor=connection.cursor ()
If there is no error, it means that our configuration was successful.
Then we need to create a model, after writing the models.py file, you need to install the model, open settings.py, find the following code, in the last line plus the name of your model.
Installed_apps = ( 'Django.contrib.admin', 'Django.contrib.auth', 'Django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'Django.contrib.staticfiles', 'MyApp',)
To verify that the model code is correct or not, a validation is required
manage.py Validate
If there is no return error, the model is described correctly, and the following code is executed to generate the SQL statement:
Python manage.py sqlall MyApp
At this point, you can see the SQL statement that created the table in the database.
Attention. At this point, the command above simply prints out the SQL statement, which is really necessary to create the various tables:
Python manage.py syncdb
At this point, the tables in the database have been created.
Django Config MySQL