#29103: sqlmigrate produces byte literal in SQL for one-off empty string default
value in TextField, CharField
               Reporter:  qlimax     |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:             |        Version:  2.0
  Migrations                         |       Keywords:  sqlmigrate, byte,
               Severity:  Normal     |  default value, one-off
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  1
                  UI/UX:  0          |
 $ 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':
     - Add field text1 to mytable


 $ python manage.py sqlmigrate myapp 0003_somechange
 -- Add field text1 to mytable
 ALTER TABLE `myapp_mytable` ADD COLUMN `text1` longtext NOT NULL;
 UPDATE `myapp_mytable` SET `text1` = b"''";

 $ 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 = [
 $ python --version
 Python 3.4.2

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

You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
For more options, visit https://groups.google.com/d/optout.

Reply via email to