mirror of https://github.com/django/django.git
Fix nullability changing code
This commit is contained in:
parent
588b839b26
commit
0354cecbfd
|
@ -495,7 +495,7 @@ class BaseDatabaseSchemaEditor(object):
|
||||||
))
|
))
|
||||||
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,
|
||||||
},
|
},
|
||||||
|
|
|
@ -153,4 +153,4 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||||
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)
|
||||||
|
|
|
@ -205,12 +205,28 @@ class SchemaTests(TestCase):
|
||||||
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):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue