首页 > 解决方案 > Run manage.py with custom database configuration

问题描述

My use case involves running python manage.py migrate with DATABASE_HOST=127.0.0.1 (since I use Cloud SQL Proxy). However, when the application is uploaded and is serving, the database URL needs to change to an actual remote URL.

Right now, I upload a special settings.py file that contains the localhost URL when I wish to run the migration command. When I deploy to cloud, I make sure to overwrite that file with a new one (which is essentially the entire file except the database URL is my remote db URL) and then upload it.

Is there a better way to achieve this? Something like python manage.py --database_url=127.0.0.1 migrate?

标签: django

解决方案


Maybe you should try making a separate file, let's say local_settings.py, in the settings.py directory. In that file copy the ALLOWED_HOSTS =["your IP"]. Then in your settings.py import it as form try: .local_settings import * except: pass But keep the ALLOWED_HOSTS=[ ] in your settings.py as it is. Hope it helps!


推荐阅读