On the production server I would like to sync the db.
If I just did that
django-admin.py syncdb it would pick the settings.py. But I have an extra settings-production.py that inheritcs from settings.
Hence I came up with this:
django-admin.py syncdb --settings=/path/to/settings_production
ImportError: Could not import settings
‘/path/to/settings_production’ (Is it on
sys.path?): Import by filename is not supported.
I googled and found someone had a similar issue here. However something that confuses me is, the WSGI.py is only read by Apache. Not if I ran the command myself. The answer there doesn’t really make sense to me.
How do I add my production_settings in sys.path manually to run syncdb?
Many Thanks,
First make sure
settings_production.pyis in the same directory assettings.py.Since you are inheriting from settings you can add at the bottom of
settings.py:If you want to only use
settings_production.pymake sure it has all the settings for your application (database, et. al.) then:DJANGO_SETTINGS_MODULE=settings_production python manage.py syncdbEdit
I was going to post it as a comment, but it became too long:
I did it this way because typically in production one only changes a few values you can import in the master
settings.py; and the last value of the variable is used (so if you set production db insettings_production.py, then that setting is used).It is easier this way since django by default will look for
settings.py; avoids having to deal with environment variables and import paths especially if you are changing minor things.There are a few draw backs to this approach; for example I can’t imagine its very portable especially if you have multiple environments (staging/testing/production/dev), as then you have multiple
from _foo_ import *statements and it can lead to problems because the order of imports becomes significant; if you forgot and kept around a straysettings_*.pyaround – for example the test environment also got the dev file because some developer forgot to remove it from the test branch.For more complex setups its easier to keep complete copies of the master
settings.pyfile; and then pointDJANGO_SETTINGS_MODULEto the python path of those files. The caveat here is that you have to make surePYTHONPATHis adjusted to include the location of your settings.For more ideas, see the SplitSettings wiki entry.