|
3 | 3 | import pytest
|
4 | 4 | from django.core.exceptions import ValidationError
|
5 | 5 | from django.core.management import call_command
|
6 |
| -from django.db import connection |
| 6 | +from django.db import connection, models |
7 | 7 | from django.db.utils import DataError
|
8 | 8 | from django.test import TestCase, TransactionTestCase, override_settings
|
| 9 | +from django.test.utils import isolate_apps |
9 | 10 |
|
10 | 11 | from django_mysql.models import EnumField
|
11 | 12 | from tests.testapp.models import EnumModel, NullableEnumModel
|
@@ -152,6 +153,28 @@ def test_adding_field_with_default(self):
|
152 | 153 | with connection.cursor() as cursor:
|
153 | 154 | assert table_name not in table_names(cursor)
|
154 | 155 |
|
| 156 | + @isolate_apps("tests.testapp") |
| 157 | + def test_alter_field_choices_changes(self): |
| 158 | + class Temp(models.Model): |
| 159 | + field = EnumField(choices=["apple"]) |
| 160 | + |
| 161 | + with connection.schema_editor() as editor: |
| 162 | + editor.create_model(Temp) |
| 163 | + |
| 164 | + @self.addCleanup |
| 165 | + def drop_table(): |
| 166 | + with connection.schema_editor() as editor: |
| 167 | + editor.delete_model(Temp) |
| 168 | + |
| 169 | + old_field = Temp._meta.get_field("field") |
| 170 | + new_field = EnumField(choices=["apple", "banana"]) |
| 171 | + new_field.set_attributes_from_name("field") |
| 172 | + |
| 173 | + with connection.schema_editor() as editor, self.assertNumQueries(1): |
| 174 | + editor.alter_field(Temp, old_field, new_field, strict=True) |
| 175 | + with connection.schema_editor() as editor, self.assertNumQueries(1): |
| 176 | + editor.alter_field(Temp, new_field, old_field, strict=True) |
| 177 | + |
155 | 178 |
|
156 | 179 | class TestFormfield(TestCase):
|
157 | 180 | def test_formfield(self):
|
|
0 commit comments