Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix nullability changing code

  • Loading branch information...
commit 0354cecbfd0cbd4e7440d56332dbb4d20f6a2fb2 1 parent 588b839
@andrewgodwin andrewgodwin authored
View
2  django/db/backends/schema.py
@@ -495,7 +495,7 @@ def alter_field(self, model, old_field, new_field, strict=False):
))
else:
actions.append((
- self.sql_alter_column_null % {
+ self.sql_alter_column_not_null % {
"column": self.quote_name(new_field.column),
"type": new_type,
},
View
2  django/db/backends/sqlite3/schema.py
@@ -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),
))
# Delete the old through table
- self.delete_model(old_field.rel.through, force=True)
+ self.delete_model(old_field.rel.through)
View
18 tests/modeltests/schema/tests.py
@@ -205,12 +205,28 @@ def test_alter(self):
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):
"""

0 comments on commit 0354cec

Please sign in to comment.
Something went wrong with that request. Please try again.