... れ、これがユニーク制約に違反するためです。 そのため、次の手順を踏む必要があります。この例では、デフォルト値を持つ非 Null の UUIDField を追加します。必要に応じて、該当するフィールドを変更してください。 モデルに default=uuid.uuid4 と unique=True 引数を持 ... ルのうちの最初のファイル)から AddField オペレーションを最後のマイグレーションにコピーし、 AddField を AlterField に変更し、 uuid と models のインポートを追加します。例: 0006_remove_uuid_null.py # Generated by Django A.B on YYYY-MM-DD HH:MM from django ... .db import migrations , models import uuid class Migration ( migrations . Migration ): dependencies = [ ( "myapp" , "0005_populate_uuid_values" ), ] operations = [ m ... ... import RandomUUID >>> Article . objects . update ( uuid = RandomUUID ()) Use django.db.models.functions.UUID4 instead. django.db.models.func ... tions.UUID4 is a cross-database version of this function. RandomUUID may be deprecated in the future. TransactionNow class Transactio ... ... されました。 QuerySet.aiterator() が以前の prefetch_related() 呼び出しをサポートするようになりました。 MariaDB 10.7 以降で、 UUIDField は CHAR(32) ではなく UUID カラムとして作成されます。詳細は、 MariaDB 10.7+ における既存の UUIDField のマイグレーション ... 前のフィールドを持つモデルは、ルックアップで create_defaults__exact を指定する必要があります。 MariaDB 10.7+ における既存の UUIDField のマイグレーション MariaDB 10.7以降では、 UUIDField は CHAR(32) カラムではなく UUID カラムとして作成されるようになりま ... した。その結果、Django < 5.0で作成された任意の UUIDField は、 CHAR(32) に基づく UUIDField サブクラスに置き換える必要があります: class Char32UUIDField ( models . UUIDField ): ... ... hes its values. This is useful especially when dealing with callables whose return values can change (e.g. datetime.now or uuid.uuid4 ): >>> import uuid >>> class UUIDCommentForm ( CommentForm ): ... identifier = forms . UUIDField ( initial = uuid . ... uuid4 ) ... >>> f = UUIDCommentForm () >>> f . get_initial_for_field ( f . fields [ "identifier" ], "identifier" ) UUID('972ca9e4-7bfe-4f5b-af7d-07 ... b3aa306334') >>> f . get_initial_for_field ( f . fields [ "identifier" ], "identifier" ) UUID('1b411fab-844e-4dec-bd4f-e9b0495f04d0') >>> # Using BoundField.initial, for comparison >>> f [ "identifier" ] . initial UU ... ... widget to add a space after custom classes ( #29221 ). Fixed PasswordResetConfirmView crash when using a user model with a UUIDField primary key and the reset URL contains an encoded primary key value that decodes to an invalid UUID ( #29206 ). Fixed ... ... json.JSONEncoder subclass to serialize data types not supported by the standard JSON serializer (e.g. datetime.datetime or UUID ). For example, you can use the DjangoJSONEncoder class. デフォルトは json.JSONEncoder です。 JSONField. decoder An option ... スと同じく、 URLField は省略可能な max_length 引数を取ります。 max_length を指定しない場合、デフォルトの 200 が使われます。 UUIDField class UUIDField ( ** options ) [ソース] A field for storing universally unique identifiers. Uses Python's UUID class. ... When used on PostgreSQL and MariaDB, this stores in a uuid datatype, otherwise in a char(32) . UUID は primary_key に代わる AutoField への良い選択肢です。 データベースはあなたのため ... ... if an authentication backend doesn't accept request and a later one does ( #29071 ). Fixed crash when entering an invalid uuid in ModelAdmin.raw_id_fields ( #29094 ). ... ... ations crashes if a migrations directory doesn't have an __init__.py file ( #29091 ). Fixed crash when entering an invalid uuid in ModelAdmin.raw_id_fields ( #29094 ). ... ... arbitrary file inclusions in admindocs ( #24625 ). Fixed a crash with QuerySet.update() on foreign keys to instances with uuid primary keys ( #24611 ). Fixed database introspection with SQLite 3.8.9 (released April 8, 2015) ( #24637 ). Updated urlpa ... ... form, such as with: a OneToOneField (or parent link used as the primary key of an inline formset's model), or a natural or UUID primary key included in the form's fields. Models using the default BigAutoField primary key were not affected. This issue ... 2026年10月08日