0

I'm trying to deploy a simple Django app on Heroku.

When I try to sync the database called "microblog" Heroku says the database doesn't exist.

Traceback:

(blog-venv)vagrant@precise64:/vagrant/projects/microblog$ heroku run python manage.py syncdb
Running `python manage.py syncdb` attached to terminal... up, run.9420
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_c
ommand_line
    utility.execute()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 533, in handle
    return self.handle_noargs(**options)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 27, in handle_n
oargs
    call_command("migrate", **options)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 115, in call_command
    return klass.execute(*args, **defaults)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 63, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/executor.py", line 17, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 48, in __init__
    self.build_graph()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 183, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migration
s
    self.ensure_schema()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.get_table_list(self.connection.cursor()):
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/__init__.py", line 165, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/__init__.py", line 138, in _cursor
    self.ensure_connection()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
    self.connect()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
    self.connect()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/__init__.py", line 122, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 134, in ge
t_new_connection
    return Database.connect(**conn_params)
  File "/app/.heroku/python/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: FATAL:  database "microblog" does not exist

I'm pretty sure the database does exist. If I run createdb microblog it says the database already exists. I'm able to sync it locally without problems with python manage.py syncdb. And if I go into the dbshell it appears to be working.

(blog-venv)vagrant@precise64:/vagrant/projects/microblog$ python manage.py dbshell
psql (9.1.14)
Type "help" for help.

microblog=#

I'm new to Django, and I'm following the instructions here: http://gettingstartedwithdjango.com/en/lessons/introduction-and-launch/#toc15

Running Django 1.7.

Any help greatly appreciated, I've been stuck here for too long! Thanks in advance.

Edit:

This is what I have in base.py (settings)

DATABASES = {}
DATABASES['default'] =  dj_database_url.config()
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
DATABASES['default']['NAME'] = 'microblog'
cydb
  • 67
  • 1
  • 9
  • Well, it exists locally but not on Heroku. Have you created the db remotely? Are you using `dj_database_url.config()` in your settings to use the database name from the environment variables? – Daniel Roseman Jan 16 '15 at 09:58
  • Thanks, Daniel. Yes, I do have dj_database_url.config() in the settings file, like they said to in the Heroku docs. I've updated the question to reflect this. Is there anything else I should add? How would I create the database remotely? I'm a complete noob so I'm not sure what other information I should give! – cydb Jan 16 '15 at 11:07
  • Well you've overridden the value set by that call. Don't do that. You don't control the db name on Heroku, which is the whole point of using dj_database_url in the first place. – Daniel Roseman Jan 16 '15 at 11:10
  • If I understand you right, you're saying I shouldn't add this: DATABASES['default']['NAME'] = 'microblog'? I added it because it was saying "settings.DATABASES is improperly configured. Please supply the NAME value." --> the same error discussed [here](http://stackoverflow.com/questions/11826326/django-error-in-heroku-please-supply-the-engine-value). I tried several things discussed on there, this was the only thing that worked. – cydb Jan 16 '15 at 11:39
  • But that's not even mentioned on that page. The top answer is correct: put in a default parameter to config() for working locally, but leave Heroku to set the value via the environment variable on the server. – Daniel Roseman Jan 16 '15 at 14:39
  • Thanks a lot, I think I figured it out! I deleted these: `DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'` and `DATABASES['default']['NAME'] = 'microblog'`, and added DATABASES = {'default': dj_database_url.config(default='postgres://username:password@localhost/microblog')}. This works and doesn't give the name error, and also gets deployed to Heroku properly. Thanks again! – cydb Jan 18 '15 at 10:38

0 Answers0