diff options
| author | Simon Charette <charette.s@gmail.com> | 2015-06-18 21:47:21 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2015-06-22 09:35:35 -0400 |
| commit | 73040e584a9ccc770593a3885f5fe40fda142e0d (patch) | |
| tree | 7eef638cc54eaa649fef9801795d0cd8b8f3410a | |
| parent | 7f155a07032caf916518beca5b33fa5a90300209 (diff) | |
Fixed #25002 -- Used PostgreSQL column type alteration USING clause.
Thanks to Dirk Uys for the report.
| -rw-r--r-- | django/db/backends/postgresql_psycopg2/schema.py | 3 | ||||
| -rw-r--r-- | tests/schema/tests.py | 14 |
2 files changed, 17 insertions, 0 deletions
diff --git a/django/db/backends/postgresql_psycopg2/schema.py b/django/db/backends/postgresql_psycopg2/schema.py index 85d9517c13..bc03a12e8d 100644 --- a/django/db/backends/postgresql_psycopg2/schema.py +++ b/django/db/backends/postgresql_psycopg2/schema.py @@ -5,9 +5,12 @@ from django.db.backends.base.schema import BaseDatabaseSchemaEditor class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): + sql_alter_column_type = "ALTER COLUMN %(column)s TYPE %(type)s USING %(column)s::%(type)s" + sql_create_sequence = "CREATE SEQUENCE %(sequence)s" sql_delete_sequence = "DROP SEQUENCE IF EXISTS %(sequence)s CASCADE" sql_set_sequence_max = "SELECT setval('%(sequence)s', MAX(%(column)s)) FROM %(table)s" + sql_create_varchar_index = "CREATE INDEX %(name)s ON %(table)s (%(columns)s varchar_pattern_ops)%(extra)s" sql_create_text_index = "CREATE INDEX %(name)s ON %(table)s (%(columns)s text_pattern_ops)%(extra)s" diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 819dafd451..66a64ef31b 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -10,6 +10,7 @@ from django.db.models import Model from django.db.models.fields import ( AutoField, BigIntegerField, BinaryField, BooleanField, CharField, DateTimeField, IntegerField, PositiveIntegerField, SlugField, TextField, + TimeField, ) from django.db.models.fields.related import ( ForeignKey, ManyToManyField, OneToOneField, @@ -447,6 +448,19 @@ class SchemaTests(TransactionTestCase): with connection.schema_editor() as editor: editor.alter_field(Note, old_field, new_field, strict=True) + def test_alter_text_field_to_time_field(self): + """ + #25002 - Test conversion of text field to time field. + """ + with connection.schema_editor() as editor: + editor.create_model(Note) + Note.objects.create(info='3:16') + old_field = Note._meta.get_field('info') + new_field = TimeField(blank=True) + new_field.set_attributes_from_name('info') + with connection.schema_editor() as editor: + editor.alter_field(Note, old_field, new_field, strict=True) + @skipIfDBFeature('interprets_empty_strings_as_nulls') def test_alter_textual_field_keep_null_status(self): """ |
