Commit 0354cecb authored by Andrew Godwin's avatar Andrew Godwin
Browse files

Fix nullability changing code

parent 588b839b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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,
                    },
+1 −1
Original line number Diff line number Diff line
@@ -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)
+17 −1
Original line number Diff line number Diff line
@@ -211,6 +211,22 @@ class SchemaTests(TestCase):
        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):
        """