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)