mirror of
https://github.com/django/django.git
synced 2025-08-27 22:14:33 +00:00
Fixed #22962 -- Default values for ArrayField with migrations.
Fields normally try to force the default value to a string. As translatable strings are not valid default values for ArrayField, we can remove this behaviour which was causing issues with some migrations. Thanks to @schinckel for the report.
This commit is contained in:
parent
e5619330e2
commit
ef9f109013
5 changed files with 102 additions and 1 deletions
|
@ -4,10 +4,11 @@ import unittest
|
|||
from django.contrib.postgres.fields import ArrayField
|
||||
from django.contrib.postgres.forms import SimpleArrayField, SplitArrayField
|
||||
from django.core import exceptions, serializers
|
||||
from django.core.management import call_command
|
||||
from django.db import models, IntegrityError, connection
|
||||
from django.db.migrations.writer import MigrationWriter
|
||||
from django import forms
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, override_settings
|
||||
from django.utils import timezone
|
||||
|
||||
from .models import IntegerArrayModel, NullableIntegerArrayModel, CharArrayModel, DateTimeArrayModel, NestedIntegerArrayModel
|
||||
|
@ -226,6 +227,13 @@ class TestMigrations(TestCase):
|
|||
statement, imports = MigrationWriter.serialize(field)
|
||||
self.assertEqual(statement, 'django.contrib.postgres.fields.ArrayField(models.CharField(max_length=20), size=None)')
|
||||
|
||||
@override_settings(MIGRATION_MODULES={
|
||||
"postgres_tests": "postgres_tests.array_default_migrations",
|
||||
})
|
||||
def test_adding_field_with_default(self):
|
||||
# See #22962
|
||||
call_command('migrate', 'postgres_tests', verbosity=0)
|
||||
|
||||
|
||||
@unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required')
|
||||
class TestSerialization(TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue