Heroku中的Django错误:“请提供ENGINE值”

时间:2021-10-02 17:14:47

I read and apply "Getting started with Django on Heroku" tutorial but ran into problem while syncing db:

我阅读并应用“在Heroku上开始使用Django”教程但在同步db时遇到了问题:

raise ImproperlyConfigured("settings.DATABASES is improperly configured." 
django.core.exceptions.ImproperlyConfigured: 
settings.DATABASES is improperly configured. Please supply the ENGINE value. 

I read Please supply the ENGINE value Django database configuration and “settings.DATABASES is improperly configured” error performing syncdb with django 1.4 but still receive same error. While executing

我读了请提供ENGINE值Django数据库配置和“settings.DATABASES配置不正确”错误执行syncdb与django 1.4但仍然收到相同的错误。执行时

heroku run python manage.py --settings=moz455.settings syncdb

I receive error "Unknown command: '--settings=moz455.settings'". How to solve this problem?

我收到错误“未知命令:' - setstings = moz455.settings'”。如何解决这个问题呢?

Version of Django is 1.4.

Django的版本是1.4。

6 个解决方案

#1


11  

I ran into the same issue, but apparently for different reasons. In the Heroku docs at https://devcenter.heroku.com/articles/django#prerequisites, it says to add the following to settings.py:

我遇到了同样的问题,但显然出于不同的原因。在https://devcenter.heroku.com/articles/django#prerequisites的Heroku文档中,它说要将以下内容添加到settings.py:

DATABASES['default'] =  dj_database_url.config()

You can pass in a parameter of:

您可以传入以下参数:

DATABASES['default'] =  dj_database_url.config(default='postgres://user:pass@localhost/dbname')

And that will allow you to develop locally and on Heroku. The part that actually SOLVES the problem I had though was that the Heroku config environment variable of DATABASE_URL was not actually set. To set this, I ran

这将允许您在本地和Heroku上进行开发。实际解决我遇到的问题的部分是DATABASE_URL的Heroku配置环境变量实际上没有设置。为此,我跑了

$ heroku config

I saw the Database URL assigned to a separate config variable. So I created a new variable:

我看到数据库URL分配给一个单独的配置变量。所以我创建了一个新变量:

$ heroko config:add DATABASE_URL={#the database url}

That solved my problem. I hope it helps anyone else with similar issues.

这解决了我的问题。我希望它可以帮助其他有类似问题的人。

#2


6  

After trying all the answers here and verifying DATABASE_URL exists, nothing worked.

在这里尝试所有答案并验证DATABASE_URL存在后,没有任何效果。

I added the second line and it worked

我添加了第二行并且它有效

DATABASES['default'] = dj_database_url.config() <--- heroko docs says this is enough
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2' <---- add this

#3


3  

Ensure that you have the database add-on installed and setup properly. See https://devcenter.heroku.com/articles/database#no-dev-database-or-no-database-url

确保已正确安装和设置数据库加载项。请参阅https://devcenter.heroku.com/articles/database#no-dev-database-or-no-database-url

I ran the following to fix the issue:

我运行以下内容来解决问题:

heroku addons:add heroku-postgresql
heroku pg:promote HEROKU_POSTGRESQL_CYAN

#4


1  

Solved it myself: in manage.py add code similar to this:

自己解决了:在manage.py中添加与此类似的代码:

CurDir = os.path.dirname(os.path.abspath(__file__))
ProjectDir = os.path.join(CurDir, "moz455")
sys.path += [ProjectDir]

And commit changes with these commands:

并使用以下命令提交更改:

git add -A
git commit -m "commit"
git push -f heroku

#5


0  

Try different order:

尝试不同的顺序:

heroku run python manage.py syncdb --settings=moz455.settings

The manage.py command looks like this:

manage.py命令如下所示:

manage.py <command> <options>

but you used it like this:

但你这样使用它:

manage.py <options> <command>

Your other problem (lack of ENGINE setting) may be caused by incorrect settings file being used during the syncdb command execution. The above should fix it also.

您的另一个问题(缺少ENGINE设置)可能是由syncdb命令执行期间使用的错误设置文件引起的。以上也应该修复它。

#6


0  

it is a little late ; but you just delete all default django database settings lines ; and add heroku's one.

有点晚了;但你只需删除所有默认的django数据库设置行;并添加heroku的一个。

it will work correctly

它会正常工作

** edit ** or simply you can use `socket.gethostname().

**编辑**或者只是你可以使用`socket.gethostname()。

example :

例子:

if socket.gethostname() == 'xx':
    DATABASE_SETTINGS ={ }

elif socket.gethostname() == 'xxx':
    another database settings...

so you can run your project under multiple hosts.

所以你可以在多个主机下运行你的项目。

#1


11  

I ran into the same issue, but apparently for different reasons. In the Heroku docs at https://devcenter.heroku.com/articles/django#prerequisites, it says to add the following to settings.py:

我遇到了同样的问题,但显然出于不同的原因。在https://devcenter.heroku.com/articles/django#prerequisites的Heroku文档中,它说要将以下内容添加到settings.py:

DATABASES['default'] =  dj_database_url.config()

You can pass in a parameter of:

您可以传入以下参数:

DATABASES['default'] =  dj_database_url.config(default='postgres://user:pass@localhost/dbname')

And that will allow you to develop locally and on Heroku. The part that actually SOLVES the problem I had though was that the Heroku config environment variable of DATABASE_URL was not actually set. To set this, I ran

这将允许您在本地和Heroku上进行开发。实际解决我遇到的问题的部分是DATABASE_URL的Heroku配置环境变量实际上没有设置。为此,我跑了

$ heroku config

I saw the Database URL assigned to a separate config variable. So I created a new variable:

我看到数据库URL分配给一个单独的配置变量。所以我创建了一个新变量:

$ heroko config:add DATABASE_URL={#the database url}

That solved my problem. I hope it helps anyone else with similar issues.

这解决了我的问题。我希望它可以帮助其他有类似问题的人。

#2


6  

After trying all the answers here and verifying DATABASE_URL exists, nothing worked.

在这里尝试所有答案并验证DATABASE_URL存在后,没有任何效果。

I added the second line and it worked

我添加了第二行并且它有效

DATABASES['default'] = dj_database_url.config() <--- heroko docs says this is enough
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2' <---- add this

#3


3  

Ensure that you have the database add-on installed and setup properly. See https://devcenter.heroku.com/articles/database#no-dev-database-or-no-database-url

确保已正确安装和设置数据库加载项。请参阅https://devcenter.heroku.com/articles/database#no-dev-database-or-no-database-url

I ran the following to fix the issue:

我运行以下内容来解决问题:

heroku addons:add heroku-postgresql
heroku pg:promote HEROKU_POSTGRESQL_CYAN

#4


1  

Solved it myself: in manage.py add code similar to this:

自己解决了:在manage.py中添加与此类似的代码:

CurDir = os.path.dirname(os.path.abspath(__file__))
ProjectDir = os.path.join(CurDir, "moz455")
sys.path += [ProjectDir]

And commit changes with these commands:

并使用以下命令提交更改:

git add -A
git commit -m "commit"
git push -f heroku

#5


0  

Try different order:

尝试不同的顺序:

heroku run python manage.py syncdb --settings=moz455.settings

The manage.py command looks like this:

manage.py命令如下所示:

manage.py <command> <options>

but you used it like this:

但你这样使用它:

manage.py <options> <command>

Your other problem (lack of ENGINE setting) may be caused by incorrect settings file being used during the syncdb command execution. The above should fix it also.

您的另一个问题(缺少ENGINE设置)可能是由syncdb命令执行期间使用的错误设置文件引起的。以上也应该修复它。

#6


0  

it is a little late ; but you just delete all default django database settings lines ; and add heroku's one.

有点晚了;但你只需删除所有默认的django数据库设置行;并添加heroku的一个。

it will work correctly

它会正常工作

** edit ** or simply you can use `socket.gethostname().

**编辑**或者只是你可以使用`socket.gethostname()。

example :

例子:

if socket.gethostname() == 'xx':
    DATABASE_SETTINGS ={ }

elif socket.gethostname() == 'xxx':
    another database settings...

so you can run your project under multiple hosts.

所以你可以在多个主机下运行你的项目。