class Agency(models.Model):
uuid = models.UUIDField(editable=False, default=uuid.uuid4())
name = models.CharField(
verbose_name='Name',
max_length=50
)
无论何时,我将应用python manage.py makemigrations
新的迁移文件。值得一提的是,我没有碰到models.py文件。
迁移文件的内容是
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='agency',
name='uuid',
field=models.UUIDField(default=uuid.UUID('890eb162-c485-49f0-87a6-ebc3e95a12b3'), editable=False),
),
migrations.AlterField(
model_name='agencycontract',
name='uuid',
field=models.UUIDField(default=uuid.UUID('f6500cbe-69ee-42c0-ad1e-80377f2a9dcf'), editable=False),
),
migrations.AlterField(
model_name='contractproduct',
name='uuid',
field=models.UUIDField(default=uuid.UUID('7bc66e61-c752-4333-b508-14b53c903e83'), editable=False),
),
]
我知道,因此我正在使用uuid函数,这就是为什么要创建它们的原因。如何停止创建文件?在此之前,真的有必要停止此迁移文件的创建吗?
答案 0 :(得分:2)
使用:
models.UUIDField(editable=False, default=uuid.uuid4) # Instead of uuid.uuid4()