Rename A Project Name
Rename the
oldprojectnamedirectory tonewprojectnamemanage.py: Changeos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'oldprojectname.settings')newprojectname/wsgi.py: Changeos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'oldprojectname.settings')newprojectname/settings.py: ChangeROOT_URLCONF = 'oldprojectname.urls'and changeWSGI_APPLICATION = 'oldprojectname.wsgi.application'newprojectname/urls.py: Change oldprojectname in a line I had added
- Rename the folder which is in your project root
- Change any references to your app in their dependencies, i.e. the app's
views.py,urls.py, 'manage.py' , andsettings.pyfiles. - Edit the database table
django_content_typewith the following command:UPDATE django_content_type SET app_label='<NewAppName>' WHERE app_label='<OldAppName>' - Also if you have models, you will have to rename the model tables. For postgres use
ALTER TABLE <oldAppName>_modelName RENAME TO <newAppName>_modelName. For mysql too I think it is the same (as mentioned by @null_radix) - (For Django >= 1.7) Update the
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. - If your
models.py's Meta Class hasapp_namelisted, make sure to rename that too (mentioned by @will). - If you've namespaced your
staticortemplatesfolders inside your app, you'll also need to rename those. For example, renameold_app/static/old_apptonew_app/static/new_app. - For renaming django
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>'

0 Comments