From 0354cecbfd0cbd4e7440d56332dbb4d20f6a2fb2 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Mon, 24 Sep 2012 12:53:37 +0100 Subject: [PATCH] Fix nullability changing code --- django/db/backends/schema.py | 2 +- django/db/backends/sqlite3/schema.py | 2 +- tests/modeltests/schema/tests.py | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/django/db/backends/schema.py b/django/db/backends/schema.py index 82fa160745..09d1202aad 100644 --- a/django/db/backends/schema.py +++ b/django/db/backends/schema.py @@ -495,7 +495,7 @@ class BaseDatabaseSchemaEditor(object): )) else: actions.append(( - self.sql_alter_column_null % { + self.sql_alter_column_not_null % { "column": self.quote_name(new_field.column), "type": new_type, }, diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py index a1fd95fe8b..c1df0c7981 100644 --- a/django/db/backends/sqlite3/schema.py +++ b/django/db/backends/sqlite3/schema.py @@ -153,4 +153,4 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): self.quote_name(old_field.rel.through._meta.db_table), )) # Delete the old through table - self.delete_model(old_field.rel.through, force=True) + self.delete_model(old_field.rel.through) diff --git a/tests/modeltests/schema/tests.py b/tests/modeltests/schema/tests.py index 5fabe6e91d..9818b0451c 100644 --- a/tests/modeltests/schema/tests.py +++ b/tests/modeltests/schema/tests.py @@ -205,12 +205,28 @@ class SchemaTests(TestCase): Author._meta.get_field_by_name("name")[0], new_field, strict=True, - ) + ) editor.commit() # Ensure the field is right afterwards columns = self.column_classes(Author) self.assertEqual(columns['name'][0], "TextField") self.assertEqual(columns['name'][1][6], True) + # Change nullability again + new_field2 = TextField(null=False) + new_field2.set_attributes_from_name("name") + editor = connection.schema_editor() + editor.start() + editor.alter_field( + Author, + new_field, + new_field2, + strict=True, + ) + editor.commit() + # Ensure the field is right afterwards + columns = self.column_classes(Author) + self.assertEqual(columns['name'][0], "TextField") + self.assertEqual(columns['name'][1][6], False) def test_rename(self): """