Heroku说我的Django应用程序的数据库不存在,我无法理解为什么

时间:2015-01-16 08:22:03

标签: python sql django postgresql heroku

我试图在Heroku上部署一个简单的Django应用程序。

当我尝试同步数据库名为"微博" Heroku说数据库不存在。

回溯:

(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

我非常确定数据库确实存在。如果我运行createdb microblog,它表示数据库已经存在。我可以在本地同步它,而python manage.py syncdb没有问题。如果我进入dbshel​​l,它似乎正在工作。

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

microblog=#

我是Django的新手,我按照此处的说明操作:http://gettingstartedwithdjango.com/en/lessons/introduction-and-launch/#toc15

运行Django 1.7。

任何帮助都非常感谢,我已经被困在这里太久了!提前谢谢。

编辑:

这就是我在base.py(设置)中所拥有的

DATABASES = {}
DATABASES['default'] =  dj_database_url.config()
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
DATABASES['default']['NAME'] = 'microblog'

0 个答案:

没有答案