How do I switch from Sqlite to Postgres in Django? -
i have django app setup sqlite , working fine. want switch postgres. installed requirement:
psycopg2==2.6
and changed settings.py to:
# build paths inside project this: os.path.join(base_dir, ...) import os base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) base_url = "localhost:8000" # quick-start development settings - unsuitable production # see https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ # security warning: keep secret key used in production secret! secret_key = '#############################################' # security warning: don't run debug turned on in production! debug = true allowed_hosts = [] # application definition installed_apps = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'raven.contrib.django.raven_compat', 'django_extensions', 'crispy_forms', 'compressor', 'rest_framework', 'accounts', 'lists', ) crispy_template_pack = "bootstrap3" middleware_classes = ( 'django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.common.commonmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.auth.middleware.sessionauthenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware', 'django.middleware.clickjacking.xframeoptionsmiddleware', 'django.middleware.security.securitymiddleware', ) root_urlconf = 'mysite.urls' templates = [ { 'backend': 'django.template.backends.django.djangotemplates', 'dirs': [], 'app_dirs': true, 'options': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'lists.context_processors.extra_context', ], }, }, ] wsgi_application = 'mysite.wsgi.application' databases = { 'default': { 'engine': 'django.db.backends.postgresql_psycopg2', 'name': 'my_database_name', 'user': 'my_database_user', 'password': 'my_database_password', 'host': '127.0.0.1', 'port': '5432', } } # internationalization # https://docs.djangoproject.com/en/1.8/topics/i18n/ language_code = 'en-us' time_zone = 'utc' use_i18n = true use_l10n = true use_tz = true # static files (css, javascript, images) # https://docs.djangoproject.com/en/1.8/howto/static-files/ staticfiles_dirs = ( 'bower_components', 'less', 'css', 'scripts', ) staticfiles_finders = ( "django.contrib.staticfiles.finders.filesystemfinder", "django.contrib.staticfiles.finders.appdirectoriesfinder", "compressor.finders.compressorfinder", ) static_url = '/static/' static_root = base_dir + '/static/' compress_precompilers = ( ('text/less', 'lessc {infile} {outfile}'), ) auth_user_model = "accounts.account"
the problem when run either:
python manage.py syncdb
or
python manage.py migrate
it creates new sqlite database! i'm on local server, localhost:8000
. postgres running fine, , i've created database appropriately in postgres. why happening , how can postgres database setup?
edit:
when print settings.databases shell, still shows:
{'default': {'atomic_requests': false, 'autocommit': true, 'conn_max_age': 0, 'engine': 'django.db.backends.sqlite3', 'host': '', 'name': '/mysite/db.sqlite3', 'options': {}, 'password': '', 'port': '', 'test': {'charset': none, 'collation': none, 'mirror': none, 'name': none}, 'time_zone': 'utc', 'user': ''}}
Comments
Post a Comment