Any way to automatically create data sources from Django database settings?

  • 4
  • 11

Would be very nice ....
Actually this should just work. How are your DB settings defined?
--
Dmitry Jemerov, Chief Technology Officer, JetBrains

In a local_settings.py file that is imported by settings.py.

Redacted excerpt:

DATABASES = {
'local': {
# dev database
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'unga_app',
'USER': 'bunga',
'PASSWORD': 'gungabunga',
'HOST': '127.0.0.1',
'PORT': '5432',
'PG_SSL': False,
},
'local_junk': {
# Junker database
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'unga_junk',
'USER': 'bunga',
'PASSWORD': 'gungabunga',
'HOST': '127.0.0.1',
'PORT': '5432',
'PG_SSL': False,
},
# ... more here
}
DATABASES['default'] = DATABASES['local']

Dmitry,

PyCharm does not appear to be fully evaluating (importing) settings.py as Python code in the same way it would be in the Django app. Our projects keep site-specific settings in an unversioned local_settings.py, which gets imported by settings.py, like so:

try:
from local_settings import *
except ImportError:
import warnings
warnings.warn('Local settings have not been found (src.conf.local_settings)')

The rest of the Django support works like a, er, charm.

Regards,
Kevin Murphy

For posterity, the obvious workaround, if you have your DATABASES settings defined in a file other than settings.py, is to just temporarily copy and paste it into settings.py and let PyCharm do its stuff. Once PyCharm has created the data source(s) for you, remove the copy. It's still easier than doing it manually.