我是Django和Heroku的新手。我剛剛在heroku文檔之後部署了我的項目。 settings.py的 部分是:Django無法在heroku上保存postgresql實例
try:
userInfo.objects.exists()
except DatabaseError:
user = userInfo()
else:
user = userInfo.objects.filter(email = email)
if user:
# check if the account is fully registered
if user.gymID:
return HttpResponse(content = 'user exist', status = 503)
user.email = email
pwmd5 = hashlib.md5(password)
user.password = pwmd5.hexdigest()
user.save()
我推到Heroku的&執行syncdb後,出現以下錯誤:models.py
class userInfo(models.Model):
"""The member information
"""
email = models.EmailField()
password = models.TextField()
account = models.CharField()
gender = models.CharField()
iconID = models.IntegerField()
gymID = models.IntegerField()
friendsNumber = models.IntegerField()
signature = models.CharField()
weibo = models.BooleanField()
在registerBasicInfo.py
的
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'dfuldndi54p56q',
'HOST': 'ec2-54-227-251-13.compute-1.amazonaws.com',
'PORT': 5432,
'USER': 'pmotmgcaijwixy',
'PASSWORD': 'Wp0Gjf66JEC4mRKkvKrF22ptnj'
}
}
# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] = dj_database_url.config()
部分發生:
2013-10-03T01:40:49.936828+00:00 app[web.1]: Internal Server Error: /ios/registerBasicInfo/json
2013-10-03T01:40:49.936828+00:00 app[web.1]: Traceback (most recent call last):
2013-10-03T01:40:49.936828+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
2013-10-03T01:40:49.936828+00:00 app[web.1]: response = callback(request, *callback_args, **callback_kwargs)
2013-10-03T01:40:49.936828+00:00 app[web.1]: File "/app/server/ios/registerBasicInfo.py", line 50, in post
2013-10-03T01:40:49.936828+00:00 app[web.1]: user.save()
2013-10-03T01:40:49.936828+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 546, in save
2013-10-03T01:40:49.936828+00:00 app[web.1]: force_update=force_update, update_fields=update_fields)
2013-10-03T01:40:49.936828+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 650, in save_base
2013-10-03T01:40:49.936828+00:00 app[web.1]: result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
2013-10-03T01:40:49.937035+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/manager.py", line 215, in _insert
2013-10-03T01:40:49.937035+00:00 app[web.1]: return insert_query(self.model, objs, fields, **kwargs)
2013-10-03T01:40:49.937035+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 1675, in insert_query
2013-10-03T01:40:49.937035+00:00 app[web.1]: return query.get_compiler(using=using).execute_sql(return_id)
2013-10-03T01:40:49.937035+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 937, in execute_sql
2013-10-03T01:40:49.937035+00:00 app[web.1]: cursor.execute(sql, params)
2013-10-03T01:40:49.937035+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/util.py", line 41, in execute
2013-10-03T01:40:49.937035+00:00 app[web.1]: return self.cursor.execute(sql, params)
2013-10-03T01:40:49.937035+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 58, in execute
2013-10-03T01:40:49.937035+00:00 app[web.1]: six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2])
2013-10-03T01:40:49.937192+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 54, in execute
2013-10-03T01:40:49.937192+00:00 app[web.1]: return self.cursor.execute(query, args)
2013-10-03T01:40:49.937192+00:00 app[web.1]: DatabaseError: current transaction is aborted, commands ignored until end of transaction block
任何想法解決它?我忍受了好幾天,感謝你的幫助!
嘗試與user = userInfo.objects.get_or_create(email = email),但仍然得到相同的錯誤 – Tate