I have changed the name of an app in Django by renaming its folder, imports and all its references (templates/indexes). But now I get this error when I try to run python manage.py runserver
Error: Could not import settings 'nameofmynewapp.settings' (Is it on sys.path?): No module named settings
How can I debug and solve this error? Any clues?
Follow these steps to change an app’s name in Django:
views.py,urls.py,manage.py, andsettings.pyfiles.django_content_typewith the following command:UPDATE django_content_type SET app_label='<NewAppName>' WHERE app_label='<OldAppName>'ALTER TABLE <oldAppName>_modelName RENAME TO <newAppName>_modelName. For mysql too, I think it is the same (as mentioned by @null_radix).django_migrationstable to avoid having your previous migrations re-run:UPDATE django_migrations SET app='<NewAppName>' WHERE app='<OldAppName>'. Note: there is some debate (in comments) if this step is required for Django 1.8+; If someone knows for sure please update here.models.py‘s Meta Class hasapp_namelisted, make sure to rename that too (mentioned by @will).staticortemplatesfolders inside your app, you’ll also need to rename those. For example, renameold_app/static/old_apptonew_app/static/new_app.models, you’ll need to changedjango_content_type.nameentry in DB. For postgreSQL, useUPDATE django_content_type SET name='<newModelName>' where name='<oldModelName>' AND app_label='<OldAppName>'__pycache__/folder inside the app must be removed, otherwise you getEOFError: marshal data too short when trying to run the server. Mentioned by @Serhii KushchenkoMeta point (If using virtualenv): Worth noting, if you are renaming the directory that contains your virtualenv, there will likely be several files in your env that contain an absolute path and will also need to be updated. If you are getting errors such as
ImportError: No module named ...this might be the culprit. (thanks to @danyamachine for providing this).Other references: you might also want to refer to the below links for a more complete picture: