Rename django app

Applications in a project were named not according to convention with Capitalization in Application names which has caused a lot of problems during data migration and migration from Sqlite to Postgres. I would like to rename it all but looks complicated task. So I will create a small TestApp with the same problem and practice on it so we can how does it work and do I have to change it or can it stay that way because it is too complicated.

cp small app and change its name..



Ok, it works fine.



I will try to change its name now.

mv TestApp/ testapps

vim testapps/apps.py



vim testapps/admin.py



vim quickbook/settings.py



grep -r "TestApp" .

vim testapps/migrations/0001_initial.py



python3 manage.py dbshell





UPDATE django_content_type SET app_label='testapps' WHERE app_label= 'TestApp';

UPDATE 1

quickbook=>\d

public | TestApp_testapp | table | quickbook

public | TestApp_testapp_id_seq | sequence | quickbook



ALTER TABLE "TestApp_testapp" RENAME TO testapps_testapp;

So, here is very important to use “” for name in uppercase.

ALTER SEQUENCE "TestApp_testapp_id_seq" RENAME TO testapps_testapp_id_seq;

Check it again!






Is it working?

quickbook=> \q

service apache2 reload




Yes, no problem it working like i expected it..






Yupi, Lets rename all other apps.

Not as difficult as it first seemed but we'll see how it works in practice.

Took about 30 minutes to figure everything out.

 

Troubleshooting (not important)

===============================

Then when we start to change to real server. With real models in relationships.

NotRelationField?  


So, so we start getting errors from indexes and relationships that have already been called.. Oops,

Delete and then recreate?

No, it is something from 

Get_model_from_relation 

https://github.com/django/django/blob/main/django/contrib/admin/utils.py 

No, you have to do explicit ref to app and model in ForeingKey then it working.. 

No, problem with indexes.

Lucky Django is open source.


Comments