Change data in DB before migrating

30 views
Skip to first unread message

sebasti...@gmail.com

unread,
Sep 3, 2023, 8:20:44 PM9/3/23
to Django users
Hallo,

sometimes it exists the problem that i change a field to another fieldtype then i want for example to move existing data in column to another column before migration of this field are running. Is there a possibility to execute a script before a field through migration are running?

Regards

David Nugent

unread,
Sep 3, 2023, 9:08:22 PM9/3/23
to Django users, sebasti...@gmail.com
Yes, this is certainly possible.

Migrations are just python scripts that follow a specific protocol/api that is detailed in the excellent django documentation. You can insert your own hand crafted migrations to handle many cases that can cater for a variety of use cases.

i would suggest though an alternative and easier approach. add a new field with a different name and change your code accordingly. once the current field is no longer of use, remove it.

HTH
/d
--
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 an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ec295628-aea3-4fb0-83d9-c5efda400729n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages