Python--django using MySQL database (i)

Source: Internet
Author: User

I've already written about how to create a Django project, and now we've got a little skeleton, and we need to do a lot of work to make this web project a bit of a meat person. Let's start with how to use the MySQL database in Django.

  premise: You already have a Django project. Installed MySQLdb, enter MySQL to create a new library (note that this must be a new library, if there are already tables in the library, there will be problems.) )

  Modify a configuration item: Open a Django project that you have already created and add your own project name to Installed_apps. Modifies the contents of the configuration in the databases item.

Installed_apps = (    'Django.contrib.admin',    'Django.contrib.auth',    'Django.contrib.contenttypes',    'django.contrib.sessions',    'django.contrib.messages',    'Django.contrib.staticfiles',    'MyProjectName',) DATABASES= {    'default': {        'ENGINE':'Django.db.backends.mysql',        'NAME':'djangotest',        'USER':'Eva_j',        'PASSWORD':'123456',        'HOST':'127.0.0.1',        'PORT':' A',    }} 

  To synchronize the database:

  

Enter the Manage. The directory in which the PY is located, executes the command manage.py the SYNCDB program automatically initializes the database, creating all the data tables that Django needs. When we write a Web application to the session, the database is not initialized, because Django stores the session information in the database.

In addition, the version after django1.9 is canceled syncdb,1.8 can also be used, but will be prompted to cancel soon. So it is recommended to initialize this later:

First Python manage.py makemigrations [appname]
Again python manage.py migrate [appname]

In this way, we can use the MySQL database in a Django project.

Python--django using MySQL Database (ii): http://www.cnblogs.com/Eva-J/p/5152823.html

Reference: http://www.cnblogs.com/fengri/articles/django5.html

Python--django using MySQL database (i)

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.