I am renaming an application to a more suitable name. In doing so, I want to ensure that South properly migrates the database (renames database tables and changes reference
Disclaimer: this isn't probably the ideal way to do it, but this is definitely easier than a lot of other approaches suggested elsewhere/earlier.
If you're using PyCharm you can try the following solution.
Refactor
> Rename
> Enter new app name (new_app
)Search for references
and Search in comments and strings
, Scope Project Files
> Refactor
Refactor
Now comes the problem.
python manage.py makemigrations
python manage.py migrate
What would this do?
old_app
)new_app
tablesIn your DB, we need to
new_app
tables by copying it from the old_app
tablesINSERT INTO new_app_table_name SELECT * FROM old_app_table_name;
You have to do this for all the models/tables in your app
SELECT setval('new_app_table_name_id_seq', (SELECT MAX(id) FROM new_app_table_name));
You have to do this for all the tables from Step 1.
I don't want to be ignorant and claim that it should be as easy as this. My project and model structure were fairly complicated but this worked like charm for me. However, if your project structure is too complicated only parts of this might work for you.
There are only two hard things in Computer Science: cache invalidation and naming things.
-- Phil Karlton