Django Config MySQL

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.