0

I am new to Django and Heroku. I just deployed my project following the heroku documents. Part of settings.py is:

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()

part of 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()

in registerBasicInfo.py:

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()

after I push to heroku & syncdb, the following error occurred:

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

Any idea to solve it? I suffered it for days, appreciate your help!

4

2 回答 2

0

将您的代码更新为:

user = userInfo.objects.get_or_create(email=email)
if user.gymID:
    return HttpResponse(content = 'user exist', status = 503)

pwmd5 = hashlib.md5(password)
user.password = pwmd5.hexdigest()
user.save()

另外,不要md5用于密码;而是使用set_password.

于 2013-10-03T05:31:24.603 回答
0

问题解决了。我没有为我的应用程序正确创建模型表,具体来说,我没有正确地将我的应用程序放入 settings.py 的 INSTALLED_APPS 中。非常基本和愚蠢的问题...

于 2013-10-05T10:25:39.787 回答