Renaming a database table or column

Hi,

After your app has grown a bit, and requirements change, it’s often good to update names that no longer seem to fit their old use case. Maybe a stronger name has been thought of, or the old name is no longer a good representation of what the code should do. For Python-land code, that’s fairly easy to change.

But how can you do this with your database definitions? Are there any good tricks for renaming database tables or columns with no downtime? The issue with using a reglar old ALTER TABLE ... RENAME migration is that running code will still try to access the database with the old column names, causing errors and crashes.

Given what I know about how Python and Django works, I can’t think of any database schema change that I would want to make without restarting Django. If you’re running Django under something like uwsgi, downtime is minimal. It would probably take longer to apply the schema changes than to restart your app.