[Django] #22424: Default value for TextField

133 views
Skip to first unread message

Django

unread,
Apr 12, 2014, 6:36:43 AM4/12/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+------------------------
Reporter: Nevsky | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------
Hi! I start testing Django 1.7beta1. I use MySQL database.
I add new TextField into my model like that:

{{{
class Article(models.Model):
title = models.CharField(max_length=200)
pub_date = models.DateField()
text = models.TextField()
text2 = models.TextField() #new TextField
}}}

When I type "python manage.py migrate" I am asked to enter default value.
But BLOB/TEXT columns can't have a default value and if i will type
something like 'blabla' then after command "python manage.py
makemigrations" i will see error. I think it is bug :)

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

Django

unread,
Apr 12, 2014, 11:37:34 PM4/12/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------

Reporter: Nevsky | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by loic84):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

Hi @Nevsky, `default` is actually handled at the Python level, not added
to the SQL, so that shouldn't be an issue.

I can reproduce that adding a `TextField()` triggers the questioner which
is probably confusing, I wonder if we can't just use `''` as default
automatically when `default=NOT_PROVIDED` and
`empty_strings_allowed=True`. Accepting the ticket on this basis.

Regarding the error with `'blabla'`, did you actually type the quotes?
That prompt interprets Python, so if you just type `blabla` it'll throw an
error because it can't find a variable named "blabla".

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

Django

unread,
Apr 13, 2014, 8:18:27 AM4/13/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------

Reporter: Nevsky | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by Nevsky):

Replying to [comment:1 loic84]:


> Regarding the error with `'blabla'`, did you actually type the quotes?
That prompt interprets Python, so if you just type `blabla` it'll throw an
error because it can't find a variable named "blabla".

Yes, I type the quotes and migration successfully making. I get error when
I trying to apply created migration because it contains default value for
field that can't have default value in MySQL database :)

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

Django

unread,
May 2, 2014, 10:54:48 AM5/2/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------

Reporter: Nevsky | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by timo):

Loic, I'm not sure using `''` as an automatic default is better than the
current situation. Why not give the user the option of entering something
else besides that (especially if `blank=True`)?

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

Django

unread,
May 5, 2014, 1:32:04 PM5/5/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------

Reporter: Nevsky | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Old description:

> Hi! I start testing Django 1.7beta1. I use MySQL database.
> I add new TextField into my model like that:
>
> {{{
> class Article(models.Model):
> title = models.CharField(max_length=200)
> pub_date = models.DateField()
> text = models.TextField()
> text2 = models.TextField() #new TextField
> }}}
>
> When I type "python manage.py migrate" I am asked to enter default value.
> But BLOB/TEXT columns can't have a default value and if i will type
> something like 'blabla' then after command "python manage.py
> makemigrations" i will see error. I think it is bug :)

New description:

Hi! I start testing Django 1.7beta1. I use MySQL database.
I add new TextField into my model like that:

{{{
class Article(models.Model):
title = models.CharField(max_length=200)
pub_date = models.DateField()
text = models.TextField()
text2 = models.TextField() #new TextField
}}}

When I type "python manage.py makemigrations" I am asked to enter default


value.
But BLOB/TEXT columns can't have a default value and if i will type

something like 'blabla' then after command "python manage.py migrate" i


will see error. I think it is bug :)

--

Comment (by loic84):

Fixed the name of the commands in the ticket description.

I originally assumed this was an issue before the migrate step, but it's
indeed an SQL issue due to one-off defaults, Django uses db defaults for
these.

The fix for MySQL is to not provide a default for BLOB/TEXT in the
SchemaEditor. Although we'll now need to propagate the default value
manually.

--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:4>

Django

unread,
May 5, 2014, 2:41:47 PM5/5/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------

Reporter: Nevsky | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by loic84):

@Nevsky could you check if this solves your problem?
https://github.com/django/django/pull/2634

--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:5>

Django

unread,
May 5, 2014, 4:28:11 PM5/5/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------

Reporter: Nevsky | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by loic84):

* cc: loic84 (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:6>

Django

unread,
May 7, 2014, 1:50:42 AM5/7/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------

Reporter: Nevsky | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by andrewgodwin):

loic84: That PR looks like the right approach to me; will MySQL reject any
default value on blob/text columns or just empty ones? Oracle has a weird
behaviour where it treats empty strings as NULL on text columns that
causes similar issues, but we have a fix for that.

--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:7>

Django

unread,
May 7, 2014, 2:02:51 AM5/7/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------

Reporter: Nevsky | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by loic84):

MySQL rejects anything even remotely related to a default for blob/text
columns (i.e. `ALTER TABLE 'table' ALTER COLUMN 'blob' DROP DEFAULT`).

--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:8>

Django

unread,
May 16, 2014, 11:56:47 AM5/16/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------
Reporter: Nevsky | Owner: syphar
Type: Bug | Status: assigned
Component: Migrations | Version: 1.7-beta-1

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by syphar):

* owner: nobody => syphar
* status: new => assigned


Comment:

I'll have a look at it and verify the fix.

(atm I get Nevsky's error when adding the column without the fix, with the
fix I get another error. But checking it.

--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:9>

Django

unread,
May 16, 2014, 12:52:53 PM5/16/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------
Reporter: Nevsky | Owner:

Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by syphar):

* owner: syphar =>
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:10>

Django

unread,
May 16, 2014, 12:56:45 PM5/16/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------
Reporter: Nevsky | Owner:

Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by syphar):

Update the PR with some comments:
https://github.com/django/django/pull/2634

short version:
PR failing when there are empty or string defaults.
But with fixed everything (in this ticket) seems fine.

--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:11>

Django

unread,
May 16, 2014, 12:56:55 PM5/16/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------
Reporter: Nevsky | Owner:

Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by syphar):

* cc: denis.cornehl@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:12>

Django

unread,
May 17, 2014, 1:31:26 PM5/17/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------
Reporter: Nevsky | Owner:

Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by loic84):

Updated the PR to fix the issue reported by @syphar and to incorporate the
fix for #22626.

Sadly the handling of bytes/strings is still less than ideal in the many
`quote_value`:
- `"` in a `default` will break SQLite and MySQL.
- Oracle doesn't support bytes so breaks on `BinaryField`.
- Oracle uses `repr` to quote `six.string_types`, which will probably
result in an extra `u` prefix.

I propose we open a new ticket to deal with this issue separately.

--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:13>

Django

unread,
May 19, 2014, 10:00:04 AM5/19/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------
Reporter: Nevsky | Owner:

Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by CollinAnderson):

#22649 SchemaEditor.quote_value is very fragile.

--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:14>

Django

unread,
May 20, 2014, 9:26:18 AM5/20/14
to django-...@googlegroups.com
#22424: Default value for TextField
---------------------------------+--------------------------------------
Reporter: Nevsky | Owner:

Type: Bug | Status: new
Component: Migrations | Version: 1.7-beta-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by Loic Bistuer <loic.bistuer@…>):

In [changeset:"6aacb4c9915c83a897dbde0b11cc46131fc7d16e"]:
{{{
#!CommitTicketReference repository=""
revision="6aacb4c9915c83a897dbde0b11cc46131fc7d16e"
Fixed #22626 -- Allow BinaryField defaults with SQlite.

Also fixes a slight issue in sqlite3.schema._remake_table where
default values where quoted with "column name" quoting rules.

Reference for quoting: http://www.sqlite.org/lang_expr.html

Thanks Shai Berger for the review. Refs #22424.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:15>

Django

unread,
May 20, 2014, 9:26:19 AM5/20/14
to django-...@googlegroups.com
#22424: Default value for TextField
-------------------------------------+-------------------------------------
Reporter: Nevsky | Owner: Loic
Type: Bug | Bistuer <loic.bistuer@…>
Component: Migrations | Status: closed
Severity: Release blocker | Version:
Keywords: | 1.7-beta-1
Has patch: 0 | Resolution: fixed
Needs tests: 0 | Triage Stage: Accepted
Easy pickings: 0 | Needs documentation: 0
| Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Loic Bistuer <loic.bistuer@…>):

* status: new => closed
* owner: => Loic Bistuer <loic.bistuer@…>
* resolution: => fixed


Comment:

In [changeset:"1d3d01b4f74f80655ac354f7a39e3908a9b41b14"]:
{{{
#!CommitTicketReference repository=""
revision="1d3d01b4f74f80655ac354f7a39e3908a9b41b14"
Fixed #22424 -- Fixed handling of default values for TextField/BinaryField
on MySQL.

Thanks syphar for the review and suggestions.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:16>

Django

unread,
May 20, 2014, 9:26:20 AM5/20/14
to django-...@googlegroups.com
#22424: Default value for TextField
-------------------------------------+-------------------------------------
Reporter: Nevsky | Owner: Loic
Type: Bug | Bistuer <loic.bistuer@…>
Component: Migrations | Status: closed
Severity: Release blocker | Version:
Keywords: | 1.7-beta-1
Has patch: 0 | Resolution: fixed
Needs tests: 0 | Triage Stage: Accepted
Easy pickings: 0 | Needs documentation: 0
| Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Andrew Godwin <andrew@…>):

In [changeset:"4e32e47348473757280ca7a8d78edf6011fe65a3"]:
{{{
#!CommitTicketReference repository=""
revision="4e32e47348473757280ca7a8d78edf6011fe65a3"
Merge pull request #2634 from loic/ticket22424

Fixed #22424 -- MySQL doesn't accept migrations' one-off default values
...
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:17>

Django

unread,
May 21, 2014, 7:05:50 AM5/21/14
to django-...@googlegroups.com
#22424: Default value for TextField
-------------------------------------+-------------------------------------
Reporter: Nevsky | Owner: Loic
Type: Bug | Bistuer <loic.bistuer@…>
Component: Migrations | Status: closed
Severity: Release blocker | Version:
Keywords: | 1.7-beta-1
Has patch: 0 | Resolution: fixed
Needs tests: 0 | Triage Stage: Accepted
Easy pickings: 0 | Needs documentation: 0
| Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"1a29675d76de00d6fad9b366fc66e8b6d541c3b6"]:
{{{
#!CommitTicketReference repository=""
revision="1a29675d76de00d6fad9b366fc66e8b6d541c3b6"
[1.7.x] Fixed #22626 -- Allow BinaryField defaults with SQlite.

Also fixes a slight issue in sqlite3.schema._remake_table where
default values where quoted with "column name" quoting rules.

Reference for quoting: http://www.sqlite.org/lang_expr.html

Thanks Shai Berger for the review. Refs #22424.

Backport of 6aacb4c991 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:18>

Django

unread,
May 21, 2014, 7:05:52 AM5/21/14
to django-...@googlegroups.com
#22424: Default value for TextField
-------------------------------------+-------------------------------------
Reporter: Nevsky | Owner: Loic
Type: Bug | Bistuer <loic.bistuer@…>
Component: Migrations | Status: closed
Severity: Release blocker | Version:
Keywords: | 1.7-beta-1
Has patch: 0 | Resolution: fixed
Needs tests: 0 | Triage Stage: Accepted
Easy pickings: 0 | Needs documentation: 0
| Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"d61b6224b09cb2aa6fb75ccecab246f91553ef7b"]:
{{{
#!CommitTicketReference repository=""
revision="d61b6224b09cb2aa6fb75ccecab246f91553ef7b"
[1.7.x] Fixed #22424 -- Fixed handling of default values for
TextField/BinaryField on MySQL.

Thanks syphar for the review and suggestions.

Backport of 1d3d01b4f7 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:19>

Reply all
Reply to author
Forward
0 new messages