You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
Hi there,
Wondering if there's any tool out there to make a zero downtime field type change easier. I want to change a django model field from one type to another, and the format of the field in the database is slightly different.
I've come up with a process I think will work, but it will be rather tedious if done manually. Wondering if there's a more automated approach or other tools out there already. I'd like to come up with a general solution for use in the future, but right now trying to tackle converting UUIDField from django-extensions to the built in django version.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
On 13/03/2019 2:40 pm, 'Kyle Mulka' via Django users wrote:
> Hi there,
>
> Wondering if there's any tool out there to make a zero downtime field
> type change easier. I want to change a django model field from one
> type to another, and the format of the field in the database is
> slightly different.
>
> I've come up with a process I think will work, but it will be rather
> tedious if done manually. Wondering if there's a more automated
> approach or other tools out there already. I'd like to come up with a
> general solution for use in the future, but right now trying to tackle
> converting UUIDField from django-extensions to the built in django
> version.
> https://github.com/django-extensions/django-extensions/issues/647 >
> I was thinking about maybe using a custom field that supports both
> types, but not exactly sure how to write a custom field that would do
> that.
I think you do need to write the second field and during the migration
use a ...
migrations.RunPython(forwards_func)
... to populate the new field from the old one.
It should all happen in a single transaction - at least it would with
PostgreSQL - and no-one would see anything until the transaction is
committed. On completion of the migration reload the web server to start
using the new model. There will be a gap before reloading when the old
software is still using the old field.
When removing the old field which can be done straight away do the same
thing and translate the data again to pick up those few records which
might have been exposed during the time before the webserver was reloaded.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 'Amitesh Sahay' via Django users
Hey Kyle, that sounds about right. It's a variation of the "Migration Recipe" I came up with a while ago: https://markusholtermann.eu/2016/04/django-migrations-recipe-2/ . My question would be if you really need the field of the new type to have the exact same name as the old one. If you can live or deal with the new type using a different name it's much easier as you don't need to migrate data twice.
/Markus
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send