﻿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
21917	Breakage in SQLite migrations	Florian Apolloner	Andrew Godwin <andrew@…>	"Error:
{{{
Applying oversight.0001_logentry_sensor...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 287, in run_from_argv
    self.execute(*args, **options.__dict__)
  File ""/home/florian/sources/django.git/django/core/management/base.py"", line 336, 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 35, in database_forwards
    field,
  File ""/home/florian/sources/django.git/django/db/backends/sqlite3/schema.py"", line 95, in add_field
    raise ValueError(""You cannot add a null=False column without a default value on SQLite."")
ValueError: You cannot add a null=False column without a default value on SQLite.
}}}

Models:
{{{
from django.db import models
from django.utils.timezone import now


class Sensor(models.Model):
    name = models.CharField(max_length=255)
    api_endpoint = models.SlugField()
    unit = models.CharField(max_length=255)
    sensor_class = models.CharField(max_length=255)
    params = models.TextField()
    current_log = models.ForeignKey('LogEntry', null=True, related_name='+')

    def __unicode__(self):
        return self.name


class LogEntry(models.Model):
    datetime = models.DateTimeField(default=now)
    sensor = models.ForeignKey(Sensor)
    value = models.CharField(max_length=255)
}}}

Migrations generated by makemigrations:
{{{
# encoding: utf8
from django.db import models, migrations
import django.utils.timezone


class Migration(migrations.Migration):

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='LogEntry',
            fields=[
                (u'id', models.AutoField(verbose_name=u'ID', serialize=False, auto_created=True, primary_key=True)),
                ('datetime', models.DateTimeField(default=django.utils.timezone.now)),
                ('value', models.CharField(max_length=255)),
            ],
            options={
            },
            bases=(models.Model,),
        ),
        migrations.CreateModel(
            name='Sensor',
            fields=[
                (u'id', models.AutoField(verbose_name=u'ID', serialize=False, auto_created=True, primary_key=True)),
                ('name', models.CharField(max_length=255)),
                ('api_endpoint', models.SlugField()),
                ('unit', models.CharField(max_length=255)),
                ('sensor_class', models.CharField(max_length=255)),
                ('params', models.TextField()),
                ('current_log', models.ForeignKey(to='oversight.LogEntry', to_field=u'id', null=True)),
            ],
            options={
            },
            bases=(models.Model,),
        ),
    ]
}}}
and:
{{{
# encoding: utf8
from django.db import models, migrations


class Migration(migrations.Migration):

    dependencies = [
        ('oversight', '0001_initial'),
    ]

    operations = [
        migrations.AddField(
            model_name='logentry',
            name='sensor',
            field=models.ForeignKey(to='oversight.Sensor', to_field=u'id'),
            preserve_default=True,
        ),
    ]
}}}"	Bug	closed	Migrations	dev	Release blocker	fixed		Florian Apolloner Andrew Godwin	Accepted	0	0	0	0	0	0
