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!