Skip to content

Commit

Permalink
Fix nullability changing code
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgodwin committed Sep 24, 2012
1 parent 588b839 commit 0354cec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion django/db/backends/schema.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def alter_field(self, model, old_field, new_field, strict=False):
)) ))
else: else:
actions.append(( actions.append((
self.sql_alter_column_null % { self.sql_alter_column_not_null % {
"column": self.quote_name(new_field.column), "column": self.quote_name(new_field.column),
"type": new_type, "type": new_type,
}, },
Expand Down
2 changes: 1 addition & 1 deletion django/db/backends/sqlite3/schema.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -153,4 +153,4 @@ def _alter_many_to_many(self, model, old_field, new_field, strict):
self.quote_name(old_field.rel.through._meta.db_table), self.quote_name(old_field.rel.through._meta.db_table),
)) ))
# Delete the old through table # Delete the old through table
self.delete_model(old_field.rel.through, force=True) self.delete_model(old_field.rel.through)
18 changes: 17 additions & 1 deletion tests/modeltests/schema/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -205,12 +205,28 @@ def test_alter(self):
Author._meta.get_field_by_name("name")[0], Author._meta.get_field_by_name("name")[0],
new_field, new_field,
strict=True, strict=True,
) )
editor.commit() editor.commit()
# Ensure the field is right afterwards # Ensure the field is right afterwards
columns = self.column_classes(Author) columns = self.column_classes(Author)
self.assertEqual(columns['name'][0], "TextField") self.assertEqual(columns['name'][0], "TextField")
self.assertEqual(columns['name'][1][6], True) 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): def test_rename(self):
""" """
Expand Down

0 comments on commit 0354cec

Please sign in to comment.