Django database migration and django migration

Source: Internet
Author: User
Tags virtual environment

Django database migration and django migration

We have compiled the code for the blog database model, but it is only Python code. Django has not translated it into a database language, therefore, these database tables are not actually created in the database.

In order for Django to complete the translation and create these database tables, we once again asked my project management assistant manage. py.Activate Virtual EnvironmentSwitch to the directory where the manage. py file is located and runpython manage.py makemigrationsAndpython manage.py migrateCommand. After the first command is run, a 000w.initial.py file is generated under the migrations \ directory of the blog application. This file is a file that Django uses to record the modifications we made to the model. Currently, three model classes are created in the models. py file. Django records these changes in 000w.initial.py.

When you enter the first command (the model data model of the application blog has been created in setting)

After Baidu, I tried the following:

 

Operate databases using Django

 

Store Data (this opens an interactive command line. First, we create a category and a tag, import three previously written model classes, and instantiateCategoryClass andTagClass for their attributesnameAssigned value. In order for Django to save the data to the databasesaveMethod .)

Try creating another article, but before creating an article, we need to create a User to specify the author of the article. The User Creation command Django has been written for us and is still running through manage. py. First, press Ctrl + c to exit the command interaction bar (several times in a row if one exit fails) and runpython manage.py createsuperuserCommand and follow the prompts to create a user: (username and password are 8 characters)

Run againpython manage.py shellGo to the Python command interaction bar and create an article:

 

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.