{{{
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.
* 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>
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>
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>
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>
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>
* cc: loic84 (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:6>
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>
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>
* 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>
* owner: syphar =>
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:10>
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>
* cc: denis.cornehl@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:12>
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>
Comment (by CollinAnderson):
#22649 SchemaEditor.quote_value is very fragile.
--
Ticket URL: <https://code.djangoproject.com/ticket/22424#comment:14>
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>
* 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>
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>
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>
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>