Updated migrations example in tutorial 2.

Follow up to a97845a823.
This commit is contained in:
Mariusz Felisiak 2020-03-10 08:53:28 +01:00 committed by GitHub
parent d82d2d49d6
commit 5da627a58f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 16 deletions

View File

@ -240,10 +240,9 @@ You should see something similar to the following:
.. code-block:: text .. code-block:: text
Migrations for 'polls': Migrations for 'polls':
polls/migrations/0001_initial.py: polls/migrations/0001_initial.py
- Create model Choice
- Create model Question - Create model Question
- Add field question to choice - Create model Choice
By running ``makemigrations``, you're telling Django that you've made By running ``makemigrations``, you're telling Django that you've made
some changes to your models (in this case, you've made new ones) and that some changes to your models (in this case, you've made new ones) and that
@ -272,14 +271,6 @@ readability):
BEGIN; BEGIN;
-- --
-- Create model Choice
--
CREATE TABLE "polls_choice" (
"id" serial NOT NULL PRIMARY KEY,
"choice_text" varchar(200) NOT NULL,
"votes" integer NOT NULL
);
--
-- Create model Question -- Create model Question
-- --
CREATE TABLE "polls_question" ( CREATE TABLE "polls_question" (
@ -288,16 +279,20 @@ readability):
"pub_date" timestamp with time zone NOT NULL "pub_date" timestamp with time zone NOT NULL
); );
-- --
-- Add field question to choice -- Create model Choice
-- --
ALTER TABLE "polls_choice" ADD COLUMN "question_id" integer NOT NULL; CREATE TABLE "polls_choice" (
ALTER TABLE "polls_choice" ALTER COLUMN "question_id" DROP DEFAULT; "id" serial NOT NULL PRIMARY KEY,
CREATE INDEX "polls_choice_7aa0f6ee" ON "polls_choice" ("question_id"); "choice_text" varchar(200) NOT NULL,
"votes" integer NOT NULL,
"question_id" integer NOT NULL
);
ALTER TABLE "polls_choice" ALTER TABLE "polls_choice"
ADD CONSTRAINT "polls_choice_question_id_246c99a640fbbd72_fk_polls_question_id" ADD CONSTRAINT "polls_choice_question_id_c5b4b260_fk_polls_question_id"
FOREIGN KEY ("question_id") FOREIGN KEY ("question_id")
REFERENCES "polls_question" ("id") REFERENCES "polls_question" ("id")
DEFERRABLE INITIALLY DEFERRED; DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX "polls_choice_question_id_c5b4b260" ON "polls_choice" ("question_id");
COMMIT; COMMIT;