Changes between Initial Version and Version 1 of Ticket #23408, comment 6


Ignore:
Timestamp:
Nov 25, 2014, 1:34:48 PM (10 years ago)
Author:
Michael Barr

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #23408, comment 6

    initial v1  
    1 I am sorry - I modified the wrong widow - wasn't supposed to submit the main window.
    2 
    3 Callables on properties for ModelFields are used for various reasons. One use case is to autocreate uuids.
     1Callables on properties for ModelFields are used for various reasons. One use case is to autocreate UUIDs (https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.UUIDField).
    42
    53My Models:
     
    4442}}}
    4543
    46 Based on the documentation, you should add the default=uuid.uuid4 on the models.UUIDField. However, you cannot do this with the current way migrations work. Django currently tries to generate the same UUID for each instance that is created. In this instance (Django 1.8 isn't released yet), you will run into issues. If default is set to a callable, I believe that it is implied that the result should be dynamically generated in Python/Django. If the functionality is to stay as stated in the result of this ticket, I would have to hand-code this migration for each app that previously existed to first create a nullable UUIDField with no default, then create a data migration to add distinct UUIDs to the Company, then write a migrations.AlterField migration to set null=False. The alternative might be to consider creating a special case for the UUIDField to allow for non-duplicated UUIDs to be created during migrations.
     44Based on the [https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.UUIDField documentation], you should add the default=uuid.uuid4 on the models.UUIDField. However, you cannot do this with the current way migrations work. Django currently tries to generate the same UUID for each instance that is created. In this instance (Django 1.8 isn't released yet), you will run into issues. If default is set to a callable, I believe that it is implied that the result should be dynamically generated in Python/Django. If the functionality is to stay as stated in the result of this ticket, I would have to hand-code this migration for each app that previously existed to first create a nullable UUIDField with no default, then create a data migration to add distinct UUIDs to the Company, then write a migrations.AlterField migration to set null=False. The alternative might be to consider creating a special case for the UUIDField to allow for non-duplicated UUIDs to be created during migrations.
Back to Top