mirror of
https://github.com/django/django.git
synced 2025-11-18 02:56:45 +00:00
Merge d8d254e559 into 1ce6e78dd4
This commit is contained in:
commit
5ac0f450d1
1 changed files with 30 additions and 1 deletions
|
|
@ -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
|
||||
-------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue