1
0
mirror of https://github.com/django/django.git synced 2025-10-26 15:16:09 +00:00

[1.8.x] Fixed #24892 -- Fixed quoting of SQL when renaming a field to AutoField in PostgreSQL

Backport of 5ab8680983 from master
This commit is contained in:
Tim Graham
2015-06-01 17:06:54 -04:00
parent 3b41850adc
commit 8911d2e20f
4 changed files with 41 additions and 14 deletions

View File

@@ -8,8 +8,8 @@ from django.db import (
)
from django.db.models import Model
from django.db.models.fields import (
BigIntegerField, BinaryField, BooleanField, CharField, DateTimeField,
IntegerField, PositiveIntegerField, SlugField, TextField,
AutoField, BigIntegerField, BinaryField, BooleanField, CharField,
DateTimeField, IntegerField, PositiveIntegerField, SlugField, TextField,
)
from django.db.models.fields.related import (
ForeignKey, ManyToManyField, OneToOneField,
@@ -20,8 +20,8 @@ from django.test import TransactionTestCase, skipIfDBFeature
from .fields import CustomManyToManyField, InheritedManyToManyField
from .models import (
Author, AuthorWithDefaultHeight, AuthorWithEvenLongerName, Book, BookWeak,
BookWithLongName, BookWithO2O, BookWithSlug, Note, NoteRename, Tag,
TagIndexed, TagM2MTest, TagUniqueRename, Thing, UniqueTest, new_apps,
BookWithLongName, BookWithO2O, BookWithSlug, IntegerPK, Note, NoteRename,
Tag, TagIndexed, TagM2MTest, TagUniqueRename, Thing, UniqueTest, new_apps,
)
@@ -38,8 +38,8 @@ class SchemaTests(TransactionTestCase):
models = [
Author, AuthorWithDefaultHeight, AuthorWithEvenLongerName, Book,
BookWeak, BookWithLongName, BookWithO2O, BookWithSlug, Note, Tag,
TagIndexed, TagM2MTest, TagUniqueRename, Thing, UniqueTest,
BookWeak, BookWithLongName, BookWithO2O, BookWithSlug, IntegerPK, Note,
Tag, TagIndexed, TagM2MTest, TagUniqueRename, Thing, UniqueTest,
]
# Utility functions
@@ -729,6 +729,22 @@ class SchemaTests(TransactionTestCase):
# field which drops the id sequence, at least on PostgreSQL.
Author.objects.create(name='Foo')
def test_alter_int_pk_to_autofield_pk(self):
"""
Should be able to rename an IntegerField(primary_key=True) to
AutoField(primary_key=True).
"""
with connection.schema_editor() as editor:
editor.create_model(IntegerPK)
old_field = IntegerPK._meta.get_field('i')
new_field = AutoField(primary_key=True)
new_field.model = IntegerPK
new_field.set_attributes_from_name('i')
with connection.schema_editor() as editor:
editor.alter_field(IntegerPK, old_field, new_field, strict=True)
def test_rename(self):
"""
Tests simple altering of fields