mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Refs #30664 -- Fixed migrations crash when altering AutoField/BigAutoField with quoted db_column on PostgreSQL.
This commit is contained in:
parent
e4684220af
commit
ff111ea5e3
@ -70,7 +70,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
|||||||
# Make ALTER TYPE with SERIAL make sense.
|
# Make ALTER TYPE with SERIAL make sense.
|
||||||
table = strip_quotes(model._meta.db_table)
|
table = strip_quotes(model._meta.db_table)
|
||||||
if new_type.lower() in ("serial", "bigserial"):
|
if new_type.lower() in ("serial", "bigserial"):
|
||||||
column = new_field.column
|
column = strip_quotes(new_field.column)
|
||||||
sequence_name = "%s_%s_seq" % (table, column)
|
sequence_name = "%s_%s_seq" % (table, column)
|
||||||
col_type = "integer" if new_type.lower() == "serial" else "bigint"
|
col_type = "integer" if new_type.lower() == "serial" else "bigint"
|
||||||
return (
|
return (
|
||||||
|
@ -636,6 +636,26 @@ class SchemaTests(TransactionTestCase):
|
|||||||
with connection.schema_editor() as editor:
|
with connection.schema_editor() as editor:
|
||||||
editor.alter_field(Author, old_field, new_field, strict=True)
|
editor.alter_field(Author, old_field, new_field, strict=True)
|
||||||
|
|
||||||
|
@isolate_apps('schema')
|
||||||
|
def test_alter_auto_field_quoted_db_column(self):
|
||||||
|
class Foo(Model):
|
||||||
|
id = AutoField(primary_key=True, db_column='"quoted_id"')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
app_label = 'schema'
|
||||||
|
|
||||||
|
with connection.schema_editor() as editor:
|
||||||
|
editor.create_model(Foo)
|
||||||
|
self.isolated_local_models = [Foo]
|
||||||
|
old_field = Foo._meta.get_field('id')
|
||||||
|
new_field = BigAutoField(primary_key=True)
|
||||||
|
new_field.model = Foo
|
||||||
|
new_field.db_column = '"quoted_id"'
|
||||||
|
new_field.set_attributes_from_name('id')
|
||||||
|
with connection.schema_editor() as editor:
|
||||||
|
editor.alter_field(Foo, old_field, new_field, strict=True)
|
||||||
|
Foo.objects.create()
|
||||||
|
|
||||||
def test_alter_not_unique_field_to_primary_key(self):
|
def test_alter_not_unique_field_to_primary_key(self):
|
||||||
# Create the table.
|
# Create the table.
|
||||||
with connection.schema_editor() as editor:
|
with connection.schema_editor() as editor:
|
||||||
|
Loading…
Reference in New Issue
Block a user