コード例 #1
0
ファイル: tests.py プロジェクト: Wilfred/django
 def test_alter(self):
     """
     Tests simple altering of fields
     """
     # Create the table
     with connection.schema_editor() as editor:
         editor.create_model(Author)
     # Ensure the field is right to begin with
     columns = self.column_classes(Author)
     self.assertEqual(columns["name"][0], "CharField")
     self.assertEqual(bool(columns["name"][1][6]), bool(connection.features.interprets_empty_strings_as_nulls))
     # Alter the name field to a TextField
     new_field = TextField(null=True)
     new_field.set_attributes_from_name("name")
     with connection.schema_editor() as editor:
         editor.alter_field(Author, Author._meta.get_field_by_name("name")[0], new_field, strict=True)
     # 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")
     with connection.schema_editor() as editor:
         editor.alter_field(Author, new_field, new_field2, strict=True)
     # Ensure the field is right afterwards
     columns = self.column_classes(Author)
     self.assertEqual(columns["name"][0], "TextField")
     self.assertEqual(bool(columns["name"][1][6]), False)
コード例 #2
0
ファイル: tests.py プロジェクト: DasAllFolks/django
 def test_alter_text_field(self):
     # Regression for "BLOB/TEXT column 'info' can't have a default value")
     # on MySQL.
     new_field = TextField(blank=True)
     new_field.set_attributes_from_name("info")
     with connection.schema_editor() as editor:
         editor.alter_field(
             Note,
             Note._meta.get_field_by_name("info")[0],
             new_field,
             strict=True,
         )
コード例 #3
0
ファイル: tests.py プロジェクト: iambibhas/django
 def test_alter_text_field(self):
     # Regression for "BLOB/TEXT column 'info' can't have a default value")
     # on MySQL.
     new_field = TextField(blank=True)
     new_field.set_attributes_from_name("info")
     with connection.schema_editor() as editor:
         editor.alter_field(
             Note,
             Note._meta.get_field_by_name("info")[0],
             new_field,
             strict=True,
         )
コード例 #4
0
ファイル: tests.py プロジェクト: trught007/django
 def test_alter(self):
     """
     Tests simple altering of fields
     """
     # Create the table
     with connection.schema_editor() as editor:
         editor.create_model(Author)
     # Ensure the field is right to begin with
     columns = self.column_classes(Author)
     self.assertEqual(columns['name'][0], "CharField")
     self.assertEqual(
         bool(columns['name'][1][6]),
         bool(connection.features.interprets_empty_strings_as_nulls))
     # Alter the name field to a TextField
     new_field = TextField(null=True)
     new_field.set_attributes_from_name("name")
     with connection.schema_editor() as editor:
         editor.alter_field(
             Author,
             Author._meta.get_field_by_name("name")[0],
             new_field,
             strict=True,
         )
     # 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")
     with connection.schema_editor() as editor:
         editor.alter_field(
             Author,
             new_field,
             new_field2,
             strict=True,
         )
     # Ensure the field is right afterwards
     columns = self.column_classes(Author)
     self.assertEqual(columns['name'][0], "TextField")
     self.assertEqual(bool(columns['name'][1][6]), False)