[Django] #30642: Unable to include default value in column_sql

10 views
Skip to first unread message

Django

unread,
Jul 16, 2019, 10:47:11 AM7/16/19
to django-...@googlegroups.com
#30642: Unable to include default value in column_sql
-------------------------------------+-------------------------------------
Reporter: jcohen28 | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 2.2
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The column_sql accepts an include_default argument, which is defaulted to
False if it is not passed.
https://github.com/django/django/blob/master/django/db/backends/base/schema.py#L202

The code that calls it in table_sql, however, doesn't pass the argument so
always defaults to False.
https://github.com/django/django/blob/master/django/db/backends/base/schema.py#L155

As a result, it does not appear possible to turn on that flag for
migrations.

I have got this functionality working by subclassing the
DatabaseSchemaEditor and overriding the `column_sql` function to default
`include_default=True`.

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

Django

unread,
Jul 16, 2019, 10:49:48 AM7/16/19
to django-...@googlegroups.com
#30642: Unable to include default value in column_sql when creating new model

-------------------------------------+-------------------------------------
Reporter: jcohen28 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/30642#comment:1>

Django

unread,
Jul 16, 2019, 11:59:33 AM7/16/19
to django-...@googlegroups.com
#30642: Unable to include default value in column_sql when creating new model
-------------------------------------+-------------------------------------
Reporter: Jeff Cohen | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Leo Shklovskii):

* cc: Leo Shklovskii (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/30642#comment:2>

Django

unread,
Jul 17, 2019, 1:31:36 AM7/17/19
to django-...@googlegroups.com
#30642: Unable to include default value in column_sql when creating new model.

-------------------------------------+-------------------------------------
Reporter: Jeff Cohen | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* type: Bug => Cleanup/optimization
* version: 2.2 => master
* resolution: => invalid


Comment:

Thanks for this report, however it is not a bug, it's rather a design
decision.

Django (for now) doesn't support default values on database level (see
[https://groups.google.com/forum/#!topic/django-
developers/3mcro17Gb40/discussion discussion]). That's why we don't add
`DEFAULT` clause on database creation because no rows would be affected.
We add `DEFAULT` clause when adding a new column to fill existing rows,
but we also immediately drop it after that (see
[https://github.com/django/django/blob/a3417282ac0464a9a2d1d7685bcfef10feed2597/django/db/backends/base/schema.py#L469-L476
add_field()]).

--
Ticket URL: <https://code.djangoproject.com/ticket/30642#comment:3>

Reply all
Reply to author
Forward
0 new messages