Move apps to different folders or to a root folder

172 views
Skip to first unread message

Nick Chang

unread,
Nov 6, 2022, 11:23:55 AM11/6/22
to Django users
Hello community,

I am trying to organize my Django project's structure as the number of apps is growing. So I am attempting to move an app in the sub-folder that contains its model definitions. The app used to be named `<sub_folder_name>.foo` and now it will be just named `foo` in the `LOCAL_APPS` setting.

It seems straightforward to do this with the following two steps:
  1. Change the reference from `<sub_folder_name>.foo` to `foo` in the whole project.
  2. Do `mv foo ..` inside the sub-folder.
Is there any DB migration work that this move requires? Or since the app name stays the same. There is nothing that needs to be done as Django does not see any change in the models. So far my investigation confirms no DB migration work is needed but would like to hear some experiences that folks might have done before.

Thanks!

Mike Dewhirst

unread,
Nov 6, 2022, 10:09:41 PM11/6/22
to django...@googlegroups.com
Should work just fine.

In any case, you can also specify the table name the model should use if you do decide to switch models between apps ...

    class Meta:
         app_label = "company"
         db_table = "common_user"
      
If your python code works and your tests pass everything should be fine.



Thanks!
--
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/5ac5eea7-f620-4d11-9796-3439231939f3n%40googlegroups.com.


-- 
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.
OpenPGP_signature

Nick Chang

unread,
Nov 10, 2022, 10:08:59 AM11/10/22
to Django users
Hi Mike,

Thanks for your reply. To further clarify about `db_table` name regarding this vertical move. The 'db_table' field is actually already specified in the models. However, if the 'db_table' name were not specified in the model and let django handle generation table names, would this move break it?  And it can be fixed by specifying the 'db_table" value in the moved models?

Thanks!

Reply all
Reply to author
Forward
0 new messages