#34946: Adding a field with default and db_default drops database level DEFAULT
-------------------------------------+-------------------------------------
     Reporter:  Simon Charette       |                    Owner:  Simon
                                     |  Charette
         Type:  Bug                  |                   Status:  assigned
    Component:  Migrations           |                  Version:  5.0
     Severity:  Release blocker      |               Resolution:
     Keywords:  sql, default,        |             Triage Stage:  Accepted
  migrations                         |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Natalia Bidart):

 Replying to [ticket:34946 Simon Charette]:
 > However adding a field with both results in the following SQL
 >
 > {{{#!sql
 > ALTER TABLE "foo" ADD COLUMN "bar" integer DEFAULT 42 NOT NULL;
 > ALTER TABLE "foo" ALTER COLUMN "bar" DROP DEFAULT;
 > }}}

 Thank you Simon for the report. I've been trying to reproduce the issue
 exactly as described to progress with the PR review. I've created a test
 app with a `Foo` model with a dummy `name` field, and then I've added a
 `bar` integer field with both `default` and `db_default`. I can't get the
 SQL that you reported, so far I'm only obtaining a SQL that would create
 an intermediary table. I think I'm missing something to craft the proper
 reproducer:
 {{{
 BEGIN;
 --
 -- Add field bar to foo
 --
 CREATE TABLE "new__ticket_34946_foo" ("id" integer NOT NULL PRIMARY KEY
 AUTOINCREMENT, "bar" integer DEFAULT 42 NOT NULL, "name" varchar(10)
 DEFAULT 'dbdef' NOT NULL);
 INSERT INTO "new__ticket_34946_foo" ("id", "name") SELECT "id", "name"
 FROM "ticket_34946_foo";
 DROP TABLE "ticket_34946_foo";
 ALTER TABLE "new__ticket_34946_foo" RENAME TO "ticket_34946_foo";
 COMMIT;
 }}}


 I've also tried this with a `Foo` model with no other field than `bar`,
 same result. Could you help me understand the steps to reproduce the error
 as reported? Thank you!

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34946#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018ba5d610bb-8710065a-5603-4d89-bec7-e86e20de45ef-000000%40eu-central-1.amazonses.com.

Reply via email to