When I run my Django app locally everything works just fine but when I deploy to Heroku using
import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://')}
For my database settings I get the following error
TypeError at /
cannot concatenate 'str' and 'NoneType' objects
you can see the full error message here http://tulsa-staging.heroku.com
Ive removed all none essential settings and isolated the problem to this setting.
So what the heck am I doing wrong here?
Why aren't you listing a host in the config string?
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
Related
I'm currently working on a django project built with django cookiecutter. I'm running both redis server and the redis client but anytime I run the django server it keeps giving the below error
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the CELERY_BROKER_URL environment variable
Below is the configurations of my .env file in my config folder
DEBUG=True
SECRET_KEY=12345
EMAIL_USE_TLS=True
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_HOST_USER=darkolawrence#gmail.com
EMAIL_HOST_PASSWORD=**********
DEFAULT_FROM_EMAIL=noreply#gmail.com
BRAINTREE_MERCHANT_ID=5pbrjk4gmztd5m8k6dg
BRAINTREE_PUBLIC_KEY=by84t6rfx9nz3vs6kegw
BRAINTREE_PRIVATE_KEY=202056899b37713b1faeb093207160ff2e
BROKER_URL=amqp://
CELERY_RESULT_BACKEND=db+sqlite:///results.sqlite
I think you need to setting.py Configure celery in the file_ BROKER_ URL, as follows:
CELERY_BROKER_URL = 'redis://hostname:6379/6'
The last bit 6 is the number represents the databases of Redis, 0-15 is available.
On Heroku, it is possible to share a database among apps using the following command:
$ heroku addons:attach <databaseName> -a <appName>
where <databaseName> is the shared database (belonging to another app) and it is attached to the app <appName> (a Django application).
I googled around for a long time but couldn't find anything describing how to access the attached database in the app. Do I need to add or modify something to Django's settings.py and what? How do I access the attached database in Django's views.py?
The following is the setting for Heroku databases and database accessing is just via ORM.
# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES = {'default':dj_database_url.config()}
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
Thanks.
Heroku always supplies configuration details as environment variables. When you do addons:attach it will print the name of the variable it has created for your attached add-on; alternatively you can specify it with the --as flag.
heroku addons:attach <databaseName> -a <appName> --as MY_ATTACHED_DB_URL
Now you can pass that variable name to the config call:
DATABASES = {
'default':dj_database_url.config(),
'course': dj_database_url.config('MY_ATTACHED_DB_URL')
}
Postgis extension is installed:
:DATABASE=> SELECT postgis_version();
postgis_version
2.2 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
I have the following buildpacks:
https://github.com/cyberdelia/heroku-geo-buildpack.git
https://github.com/heroku/heroku-buildpack-python.git
When I run manage.py migrate I get:
AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
I am using the hobby deb postgres which now supports postgis
https://devcenter.heroku.com/changelog-items/792
Do I need to install a different build pack or add some additional configuration? Everything works locally using postgis.
I finally had some time to go back and look at this. It turns out the issue was Heroku was not importing my settings correctly. I was using cookiecutter-django settings scheme that imports common settings into production and for some reason Heroku was not working as expected.
My common settings contained:
DATABASES['default']['ATOMIC_REQUESTS'] = True
DATABASES['default']['ENGINE'] = "django.contrib.gis.db.backends.postgis"
And my production contained:
DATABASES['default'] = env.db("DATABASE_URL")
Heroku did not import those common settings. When I checked in the django shell in heroku the production settings had
'ENGINE': 'django.db.backends.postgresql_psycopg2', 'ATOMIC_REQUESTS': False
After adding DATABASES['default']['ENGINE'] = "django.contrib.gis.db.backends.postgis" to production settings everything is working.
Does anybody know what could be going wrong with importing settings correctly from common.py? It seems to import the rest of the settings correctly, just not the database ones.
I am having a problem getting django to recognize my heroku postgres db. Usually the following configuration work fine, but for some reason it has stopped working on my most recent application.
In settings.py, I added the following code.
import dj_database_url
DATABASES['default'] = dj_database_url.config()
print DATABASES['default']
it prints out {'default':{}}
the heroku pg:info command returns what looks to be normal:
=== HEROKU_POSTGRESQL_WHITE_URL
Plan: Dev
Status: available
Connections: 1
PG Version: 9.2.4
Created: 2013-08-06 15:40 UTC
Data Size: 6.3 MB
Tables: 0
Rows: 0/10000 (In compliance)
Fork/Follow: Unsupported
When I go to use the database it returns
settings.DATABASES is improperly configured.
Any thoughts on why dj_database_url.config() is not properly parsing the database configurations?
Thank you for the thoughts.
EDIT:
Still don't know the reason for the above behavior, but I found a work around. I had to add the postgres db to the app before the initial push. For some reason it wasn't finding it if it was added after the first push.
This should be your db settings
DATABASES['default'] = dj_database_url.config(default='postgres://user:passwprd#host/db')
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
I was looking through http://lincolnloop.com/blog/2009/sep/15/using-django-inside-tornado-web-server/ and I thought it was interesting and useful to use parts of Django if we need it in Tornado.
Based on the setup in http://lincolnloop.com/blog/2009/sep/15/using-django-inside-tornado-web-server/ how can we use manage.py syncdb ?
Here's what i have tried so far:
I've tried shifting manage.py to the same folder as the tornado project, and ran manage.py syncdb but it returns saying that settings.py is not found.
than i tried to move setting.py to the same folder and ran manage.py again. It tells me that no fixtures found. This time round, I have no idea how to configure settings.py since this is not a Django project.
Any advice or thoughts?
=================updates======================
Hi all,
continuing from the above an using advice provided by Agos,
i've tried running python manage.py syncdb --settings=dj_tornado and it returns
`"Error: Can't find the file 'settings.py'` in the directory containing 'manage.py'`. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings module.
(If the file settings.py does indeed exist, it's causing an ImportError somehow.)"
So what i did is to run django-admin.py syncdb --settings=dj_tornado and it returns "django.core.exceptions.ImproperlyConfigured: You haven't set the database ENGINE setting yet."
But the weird thing is that the database engine has been set. How would I go about fixing this? i'm using django 1.2.3 and Tornado 0.2 by the way.
=================updates again======================
Hi all,
i've applied the advice provided by Agos, with a settings.py file in teh same folder as manage.py, and ran the command django-admin.py syncdb --settings=dj_tornado.
I still received the error:
django.core.exceptions.ImproperlyConfigured: You haven't set the database ENGINE setting yet.
But i have already configured the database based engine as follows:
in dj_tornado.py:
from django.conf import settings
settings.configure(
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'dev.db',
}
}
)
I'm kind of at my wits end. How do i use syncdb outside of Django project?
Best.
If I got it correctly, you can just use the --settings switch to point manage.py to the dj_tornado.py, which is your settings file after all
Update 1
from the help, available at python manage.py help:
Options:
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
So I would try this:
python manage.py syncdb --settings=dj_tornado
Update 2
Another error, another update to the answer!
First of all, consider that that blog post is quite old (september 2009). Django's DATABASES setting has been updated since 1.2.
The syntax in the blog post was:
settings.configure(DATABASE_ENGINE='sqlite3', DATABASE_NAME='dev.db')
With Django 1.2.X this is surely not correct. This would be the equivalent version:
settings.configure(DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'dev.db'
}
})
(sorry for the horrible formatting of the code).
If this still won't work, I'd consider creating a “standard” Django settings file to import. But my bet is on the db settings syntax.
Last update, I swear
Have you tried using django-admin.py again with the new syntax? If so, and still didn't work, a minimal settings.py would be just this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'dev.db'
}
}
You can also keep the original configuration inside dj_tornado.py and use settings.py just to do syncdb.