summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-01-25 00:09:56 +0000
committerAndrew Godwin <andrew@aeracode.org>2014-01-25 00:10:25 +0000
commit2a30b39f40265c9228fc2e706bcb6e1df1aae991 (patch)
tree7e03de71322194db39bfe428e9e23264e20e7d79 /tests
parent06bd181f97e5e5561ae7e80efae4c38ee670773f (diff)
Fixed #21783: More SQLite default fun with nulls.
Diffstat (limited to 'tests')
-rw-r--r--tests/schema/tests.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 88388ac0b4..99805c45c7 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -4,7 +4,7 @@ import unittest
from django.test import TransactionTestCase
from django.db import connection, DatabaseError, IntegrityError, OperationalError
-from django.db.models.fields import IntegerField, TextField, CharField, SlugField
+from django.db.models.fields import IntegerField, TextField, CharField, SlugField, BooleanField
from django.db.models.fields.related import ManyToManyField, ForeignKey
from django.db.transaction import atomic
from .models import (Author, AuthorWithM2M, Book, BookWithLongName,
@@ -185,6 +185,32 @@ class SchemaTests(TransactionTestCase):
self.assertEqual(columns['surname'][1][6],
connection.features.interprets_empty_strings_as_nulls)
+ def test_add_field_temp_default_boolean(self):
+ """
+ Tests adding fields to models with a temporary default where
+ the default is False. (#21783)
+ """
+ # Create the table
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ # Ensure there's no age field
+ columns = self.column_classes(Author)
+ self.assertNotIn("age", columns)
+ # Add some rows of data
+ Author.objects.create(name="Andrew", height=30)
+ Author.objects.create(name="Andrea")
+ # Add a not-null field
+ new_field = BooleanField(default=False)
+ new_field.set_attributes_from_name("awesome")
+ with connection.schema_editor() as editor:
+ editor.add_field(
+ Author,
+ new_field,
+ )
+ # Ensure the field is right afterwards
+ columns = self.column_classes(Author)
+ self.assertEqual(columns['awesome'][0], "BooleanField")
+
def test_alter(self):
"""
Tests simple altering of fields