Fix nullability changing code

This commit is contained in:
Andrew Godwin 2012-09-24 12:53:37 +01:00
parent 588b839b26
commit 0354cecbfd
3 changed files with 19 additions and 3 deletions

View File

@ -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,
},

View File

@ -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)

View File

@ -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):
"""