0

I created a custom migration "0000_initial_data.py" and I want that to get applied after all the other migrations are done. Though when I try to use ____latest____ in the dependencies I get "dependencies reference nonexistent parent node" error I feel it is trying to find ____latest____ named migration in the folder but it is unable to find. I got an idea of finding the latest migration in myapp/migrations/ using "ls -Art | tail -n 1" which gave me 0001_initial.pyc [pyc] file rather than the latest migration .py file. Though even if I get the name of the latest migration I have to replace in the custom migration file using a shell script like

$ replace '__latest__' 'output of ls -Art' -- 0000_initial_data.py 

as am automating my deployment. I would like to know the best way to get the latest migration from all myapps in the project and plug my custom migration after it.

Note: using django==1.8.13, ubuntu 14.04, python 2.7

1 Answers1

1

Generally custom migrations are used for changing existing data. If you wanna create new data, I recommend you to put your code inside a management command and run that after all migrations.

Mehdi Pourfar
  • 488
  • 4
  • 13
  • 1
    That actually worked for me. followed steps here http://janetriley.net/2014/11/quick-how-to-custom-django-management-commands.html to create custom command and it worked like a charm. Thanks @Mehdi Pourfar – Naresh Ghanate Sep 25 '16 at 09:12
  • 1
    If you are using django_extensions, you can create paths and files by simply calling this command: `./manage.py create_command app_name` – Mehdi Pourfar Sep 25 '16 at 09:19
  • That would have saved my file creation time. Though had to create 2 folders and 1 file so din't each much of my time. Thanks for this as well, should help me in future apps. – Naresh Ghanate Sep 25 '16 at 09:21