Opened 11 years ago

Last modified 11 years ago

#22424 closed Bug

Default value for TextField — at Version 4

Reported by: Vitaly Yakubenko Owned by: nobody
Component: Migrations Version: 1.7-beta-1
Severity: Release blocker Keywords:
Cc: loic84, denis.cornehl@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by loic84)

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 :)

Change History (4)

comment:1 by loic84, 11 years ago

Triage Stage: UnreviewedAccepted

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".

in reply to:  1 comment:2 by Vitaly Yakubenko, 11 years ago

Replying to loic84:

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.

Yes I think correct is to use "None" as default in this instance.

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 confused commands "migrate" and "magemigrations" in ticked description. 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 :)

Last edited 11 years ago by Vitaly Yakubenko (previous) (diff)

comment:3 by Tim Graham, 11 years ago

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=False)?

Last edited 11 years ago by Tim Graham (previous) (diff)

comment:4 by loic84, 11 years ago

Description: modified (diff)

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.

Note: See TracTickets for help on using tickets.
Back to Top