Let makemigrations know a data migration is required ?

59 views
Skip to first unread message

Stu.Axon

unread,
Aug 11, 2022, 3:55:40 PMAug 11
to Django users
I've got a table that has a list of classnames (that aren't models) that are subclasses of a class.

I'd like to hook into makemigrations and generate data migrations to add / remove data as required - any idea the best way I can do this ?

fawemimo olawale

unread,
Aug 11, 2022, 5:19:19 PMAug 11
to django...@googlegroups.com
On Thu, 11 Aug 2022 at 20:56, Stu.Axon <stu....@gmail.com> wrote:
I've got a table that has a list of classnames (that aren't models) that are subclasses of a class.

I'd like to hook into makemigrations and generate data migrations to add / remove data as required - any idea the best way I can do this ?

--
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/765737bd-2139-45ef-a6ed-6eb802d58f6cn%40googlegroups.com.

M Adnan

unread,
Aug 11, 2022, 5:42:42 PMAug 11
to django...@googlegroups.com
When we create a modal or change a modal than we use these two commands python manage.py makemigrations here our table are created and to insert these table into database this command is necessary python manage.py migrate. I hope you will understand this.

On Fri, 12 Aug 2022, 12:56 am Stu.Axon, <stu....@gmail.com> wrote:
I've got a table that has a list of classnames (that aren't models) that are subclasses of a class.

I'd like to hook into makemigrations and generate data migrations to add / remove data as required - any idea the best way I can do this ?

--

Durai pandian

unread,
Aug 12, 2022, 9:42:45 AMAug 12
to django...@googlegroups.com
Django data migration can help in your case.


1. add empty migration
2. add your data manipulation logic there.




--
Thanks & Regards,
Durai pandian
Email    : ddp...@gmail.com

Stu.Axon

unread,
Aug 12, 2022, 10:17:48 AMAug 12
to Django users
Are you suggesting I should have my code generate the file with the data migration in it manually ?

I was thinking there might be some signal or something I could raise that would tell django a migration was required.

The I was thinking thinking I could hook into makemigrations to and generate the data migration there somehow.

Durai pandian

unread,
Aug 12, 2022, 10:52:14 AMAug 12
to django...@googlegroups.com
Since you have source table, you can check "inspectdb" command to generate model for that table.

Try using the generated model into new migration.

Hope this helps.

Gav O'Connor

unread,
Aug 12, 2022, 11:57:50 AMAug 12
to Django users
You can create a data migration using the `--empty` switch. See the docs: https://docs.djangoproject.com/en/4.1/topics/migrations/#data-migrations

Bayo Izekor

unread,
Aug 12, 2022, 12:05:52 PMAug 12
to django...@googlegroups.com
please explain what you want to achieve for better support

Reply all
Reply to author
Forward
0 new messages