﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29103	sqlmigrate produces byte literal in SQL for one-off string default value in TextField, CharField on MySQL	Qlimax	nobody	"
{{{
$ python manage.py makemigrations myapp
You are trying to add a non-nullable field 'text1' to mytable without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
 2) Quit, and let me add a default in models.py
Select an option: 1
Please enter the default value now, as valid Python
The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.now
Type 'exit' to exit this prompt
>>> ''
Migrations for 'myapp':
  myapp/migrations/0003_somechange.py
    - Add field text1 to mytable

Done.

$ python manage.py sqlmigrate myapp 0003_somechange 
BEGIN;
--
-- Add field text1 to mytable
--
ALTER TABLE `myapp_mytable` ADD COLUMN `text1` longtext NOT NULL;
UPDATE `myapp_mytable` SET `text1` = b""''"";
COMMIT;

$ cat myapp/migrations/0003_somechange.py 
# Generated by Django 2.0.2 on 2018-02-02 11:56

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('myapp', '0002_auto_20180202_1154'),
    ]

    operations = [
        migrations.AddField(
            model_name='mytable',
            name='text1',
            field=models.TextField(default=''),
            preserve_default=False,
        ),
    ]
$ python --version
Python 3.4.2
}}}

"	Bug	closed	Migrations	2.0	Normal	fixed	sqlmigrate, byte, default value, one-off		Ready for checkin	1	0	0	0	0	0
