This commit is contained in:
Christoph Bülter 2025-11-17 13:45:10 +01:00 committed by GitHub
commit 5ac0f450d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -529,7 +529,36 @@ Should become::
uuid = Char32UUIDField(primary_key=True, default=uuid.uuid4)
Running the :djadmin:`makemigrations` command will generate a migration
containing a no-op ``AlterField`` operation.
containing a no-op ``AlterField`` operation. By default, new
``UUIDField`` instances will use the ``UUID`` column type. If a
``CHAR(32)`` column is needed, for example if you want to ensure
consistency with existing columns, use a ``Char32UUIDField``.
----
Alternatively, existing ``UUIDField`` columns could be altered in the
database to use a ``UUID`` column, by running a ``RunSQL`` operation in
a data migration::
class Migration(migrations.Migration):
...
operations = [
migrations.RunSQL(
sql="""
ALTER TABLE my_app_model1 MODIFY my_uuid_field1 UUID NOT NULL;
ALTER TABLE my_app_model2 MODIFY my_uuid_field2 UUID NOT NULL;
""",
elidable=True,
)
]
Once migrated, this would need no additional consideration when adding
new ``UUIDField`` instances.
Please note that for larger tables or when ``UUIDFields`` are used as
primary keys or in constraints, this operation could either require a
lengthy table rebuild, or even end up failing to migrate the constraints
without additional steps (see :ticket:`33507` for details).
Miscellaneous
-------------