mirror of
https://github.com/django/django.git
synced 2025-01-08 17:37:20 +00:00
Fixed #33919 -- Fixed adding AutoFields on PostgreSQL.
Thanks Jack Calvin Brown for the report.
Regression in 2eea361eff
.
This commit is contained in:
parent
4fcba800b8
commit
5c803bc070
@ -637,6 +637,8 @@ class BaseDatabaseSchemaEditor:
|
|||||||
# It might not actually have a column behind it
|
# It might not actually have a column behind it
|
||||||
if definition is None:
|
if definition is None:
|
||||||
return
|
return
|
||||||
|
if col_type_suffix := field.db_type_suffix(connection=self.connection):
|
||||||
|
definition += f" {col_type_suffix}"
|
||||||
# Check constraints can go on the column SQL here
|
# Check constraints can go on the column SQL here
|
||||||
db_params = field.db_parameters(connection=self.connection)
|
db_params = field.db_parameters(connection=self.connection)
|
||||||
if db_params["check"]:
|
if db_params["check"]:
|
||||||
|
@ -35,3 +35,7 @@ Bugfixes
|
|||||||
|
|
||||||
* Fixed a bug in Django 4.1 that caused an incorrect validation of
|
* Fixed a bug in Django 4.1 that caused an incorrect validation of
|
||||||
``CheckConstraint()`` with range fields on PostgreSQL (:ticket:`33905`).
|
``CheckConstraint()`` with range fields on PostgreSQL (:ticket:`33905`).
|
||||||
|
|
||||||
|
* Fixed a regression in Django 4.1 that caused an incorrect migration when
|
||||||
|
adding ``AutoField``, ``BigAutoField``, or ``SmallAutoField`` on PostgreSQL
|
||||||
|
(:ticket:`33919`).
|
||||||
|
@ -795,6 +795,31 @@ class SchemaTests(TransactionTestCase):
|
|||||||
# Introspection treats BLOBs as TextFields
|
# Introspection treats BLOBs as TextFields
|
||||||
self.assertEqual(columns["bits"][0], "TextField")
|
self.assertEqual(columns["bits"][0], "TextField")
|
||||||
|
|
||||||
|
@isolate_apps("schema")
|
||||||
|
def test_add_auto_field(self):
|
||||||
|
class AddAutoFieldModel(Model):
|
||||||
|
name = CharField(max_length=255, primary_key=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
app_label = "schema"
|
||||||
|
|
||||||
|
with connection.schema_editor() as editor:
|
||||||
|
editor.create_model(AddAutoFieldModel)
|
||||||
|
self.isolated_local_models = [AddAutoFieldModel]
|
||||||
|
old_field = AddAutoFieldModel._meta.get_field("name")
|
||||||
|
new_field = CharField(max_length=255)
|
||||||
|
new_field.set_attributes_from_name("name")
|
||||||
|
new_field.model = AddAutoFieldModel
|
||||||
|
with connection.schema_editor() as editor:
|
||||||
|
editor.alter_field(AddAutoFieldModel, old_field, new_field)
|
||||||
|
new_auto_field = AutoField(primary_key=True)
|
||||||
|
new_auto_field.set_attributes_from_name("id")
|
||||||
|
new_auto_field.model = AddAutoFieldModel()
|
||||||
|
with connection.schema_editor() as editor:
|
||||||
|
editor.add_field(AddAutoFieldModel, new_auto_field)
|
||||||
|
# Crashes on PostgreSQL when the GENERATED BY suffix is missing.
|
||||||
|
AddAutoFieldModel.objects.create(name="test")
|
||||||
|
|
||||||
def test_remove_field(self):
|
def test_remove_field(self):
|
||||||
with connection.schema_editor() as editor:
|
with connection.schema_editor() as editor:
|
||||||
editor.create_model(Author)
|
editor.create_model(Author)
|
||||||
|
Loading…
Reference in New Issue
Block a user