Answer the question
In order to leave comments, you need to log in
Why is DEFERRABLE INITIALLY DEFERRED needed as a result of sqlmigrate for model add migration?
Can you please tell me why DEFERRABLE INITIALLY DEFERRED is used when creating a model table? This is the result I got:
BEGIN;
--
-- Create model Post
--
CREATE TABLE "blog_post" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "title" varchar(250) NOT NULL, "slug" varchar(250) NOT NULL, "b
ody" text NOT NULL, "publish" datetime NOT NULL, "created" datetime NOT NULL, "updated" datetime NOT NULL, "status" varchar(10) NOT NULL,
"author_id" integer NOT NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE INDEX "blog_post_slug_b95473f2" ON "blog_post" ("slug");
CREATE INDEX "blog_post_author_id_dd7a8485" ON "blog_post" ("author_id");
COMMIT;
IMMEDIATE constraints are checked at the end of each statement, while DEFERRED constraints are deferred until the transaction commits. The IMMEDIATE or DEFERRED mode is set for each constraint independently.
Answer the question
In order to leave comments, you need to log in
Your generated SQL is not valid for postgresql. The AUTOINCREMENT keyword does not exist.
And about deferred constraints:
cc=> begin;
BEGIN
cc=> insert into blog_post (author_id) values (100);
INSERT 0 1
cc=> commit;
ERROR: insert or update on table "blog_post" violates foreign key constraint "blog_post_author_id_fkey"
ПОДРОБНОСТИ: Key (author_id)=(100) is not present in table "auth_user".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question