Differences between Django learning migrate and makemigrations: djangomigrate

Source: Internet
Author: User

Differences between Django learning migrate and makemigrations: djangomigrate

This article mainly studies the differences between migrate and makemigrations in Django, as detailed below.

After you modify the content of model. py, run the following command:

Python manger.py makemigrations

This is equivalent to setting up the migrations directory under the app and recording all your modes. py changes, such as 0001_initial.py, but this change has not worked on database files.

You can manually open this file to see what it is

Then run the command

python manager.py migrate

Use the change action to a database file, such as table generation.

When the makemigrations generates the 0001_initial.py file, you can check what the migrations corresponds

python manger.py sqlmigrate theapp 0001

It looks like this:

BEGIN;CREATE TABLE "polls_choice" (  "id" serial NOT NULL PRIMARY KEY,  "choice_text" varchar(200) NOT NULL,  "votes" integer NOT NULL);CREATE TABLE "polls_question" (  "id" serial NOT NULL PRIMARY KEY,  "question_text" varchar(200) NOT NULL,  "pub_date" timestamp with time zone NOT NULL);ALTER TABLE "polls_choice" ADD COLUMN "question_id" integer NOT NULL;ALTER TABLE "polls_choice" ALTER COLUMN "question_id" DROP DEFAULT;CREATE INDEX "polls_choice_7aa0f6ee" ON "polls_choice" ("question_id");ALTER TABLE "polls_choice" ADD CONSTRAINT "polls_choice_question_id_246c99a640fbbd72_fk_polls_question_id"  FOREIGN KEY ("question_id")  REFERENCES "polls_question" ("id")  DEFERRABLE INITIALLY DEFERRED;COMMIT;

Summary

The above is all about the differences between Django's learning of migrate and makemigrations. I hope to help you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!

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.