#21783: Adding a non-nullable field fails on SQLite
-------------------------------------------+------------------------
               Reporter:  apollo13         |          Owner:
                   Type:  Bug              |         Status:  new
              Component:  Migrations       |        Version:  master
               Severity:  Release blocker  |       Keywords:
           Triage Stage:  Accepted         |      Has patch:  0
    Needs documentation:  0                |    Needs tests:  0
Patch needs improvement:  0                |  Easy pickings:  0
                  UI/UX:  0                |
-------------------------------------------+------------------------
 as the title says; just add a new field to a model and provide a default
 for existing rows; will fail during migration with:
 {{{
 Operations to perform:
   Synchronize unmigrated apps: admin, contenttypes, auth, sessions
   Apply all migrations: oversight
 Synchronizing apps without migrations:
   Creating tables...
   Installing custom SQL...
   Installing indexes...
 Installed 0 object(s) from 0 fixture(s)
 Running migrations:
   Applying oversight.0003_sensor_unit...Traceback (most recent call last):
   File "./manage.py", line 10, in <module>
     execute_from_command_line(sys.argv)
   File
 "/home/florian/sources/django.git/django/core/management/__init__.py",
 line 427, in execute_from_command_line
     utility.execute()
   File
 "/home/florian/sources/django.git/django/core/management/__init__.py",
 line 419, in execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File "/home/florian/sources/django.git/django/core/management/base.py",
 line 244, in run_from_argv
     self.execute(*args, **options.__dict__)
   File "/home/florian/sources/django.git/django/core/management/base.py",
 line 291, in execute
     output = self.handle(*args, **options)
   File
 "/home/florian/sources/django.git/django/core/management/commands/migrate.py",
 line 145, in handle
     executor.migrate(targets, plan, fake=options.get("fake", False))
   File
 "/home/florian/sources/django.git/django/db/migrations/executor.py", line
 60, in migrate
     self.apply_migration(migration, fake=fake)
   File
 "/home/florian/sources/django.git/django/db/migrations/executor.py", line
 94, in apply_migration
     migration.apply(project_state, schema_editor)
   File
 "/home/florian/sources/django.git/django/db/migrations/migration.py", line
 97, in apply
     operation.database_forwards(self.app_label, schema_editor,
 project_state, new_state)
   File
 "/home/florian/sources/django.git/django/db/migrations/operations/fields.py",
 line 30, in database_forwards
     schema_editor.add_field(from_model,
 to_model._meta.get_field_by_name(self.name)[0])
   File
 "/home/florian/sources/django.git/django/db/backends/sqlite3/schema.py",
 line 91, in add_field
     self._remake_table(model, create_fields=[field])
   File
 "/home/florian/sources/django.git/django/db/backends/sqlite3/schema.py",
 line 63, in _remake_table
     self.quote_name(model._meta.db_table),
   File "/home/florian/sources/django.git/django/db/backends/schema.py",
 line 96, in execute
     cursor.execute(sql, params)
   File "/home/florian/sources/django.git/django/db/backends/utils.py",
 line 77, in execute
     return super(CursorDebugWrapper, self).execute(sql, params)
   File "/home/florian/sources/django.git/django/db/backends/utils.py",
 line 61, in execute
     return self.cursor.execute(sql, params)
   File "/home/florian/sources/django.git/django/db/utils.py", line 93, in
 __exit__
     six.reraise(dj_exc_type, dj_exc_value, traceback)
   File "/home/florian/sources/django.git/django/db/backends/utils.py",
 line 61, in execute
     return self.cursor.execute(sql, params)
   File
 "/home/florian/sources/django.git/django/db/backends/sqlite3/base.py",
 line 489, in execute
     return Database.Cursor.execute(self, query, params)
 django.db.utils.IntegrityError: NOT NULL constraint failed:
 oversight_sensor__new.unit
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21783>
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 
https://groups.google.com/d/msgid/django-updates/051.ee40b1d11deef7dc094060ab085a6e25%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to