No query results on heroku, but working on local development server

22 views
Skip to first unread message

Joel Mathew

unread,
Dec 16, 2018, 2:18:22 PM12/16/18
to django...@googlegroups.com

I just started using heroku today. I was testing a web application, and got different results on using django app from local development server and heroku. I had imported to the database by running the django development webserver. Since the postgredb uses the amazonaws url, I assumed that this data would be available to the production server on heroku.

From my local django webserver, the following search yields correct results:

from django.db.models import CharField
from django.db.models.functions import Lower
CharField.register_lookup(Lower, "lower")
import logging
logger = logging.getLogger('testlogger')
logger.info('This is a simple log message')
items_set = []
if request.method == 'POST':
    print(request.POST.get)
    form = CGHSMetaForm(request.POST)
    name = request.POST.get('name').lower()
    items_set = CGHSRates.objects.filter(
        name__lower__contains=name).order_by('name')
    print(items_set)
    logger.info(items_set)
else:
    form = CGHSMetaForm()

return render(
    request, 'app/cghs_search.html', {
        'rnd_num': randomnumber(),       
        'form': form,
        'items': items_set,
    })

I get the following results:

Code
Name
Rate
1098
After Mastectomy (Reconstruction)Mammoplasty
Rs 13800.0
364
Local mastectomy-simple
Rs 14548.0
251
Mastoidectomy
Rs 17193.0

On heroku, however, I receive an empty result.

The database is the default heroku database, a postgre db, defined by the following settings in settings.py:

import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://kpnbcpyqtxxjqu:2c86exffsdff0d789e7f3b29d7...@ec2-53-22-46-10.compute-1.amazonaws.com:5432/dful1l3ra7nknn')}

Why does the same database when accessed on different servers yield different results? What should I be checking?

Ketan Varia

unread,
Dec 17, 2018, 2:36:20 PM12/17/18
to django...@googlegroups.com
Hi Mathew,

I am still learner of django but I had faced similar issue while deploying my code to heroku.  I followed below steps.

- local server installed postgres database and updated settings.py
- taken local backup of database 
         pg_dump -U postgres  --no-owner --no-acl -f   <backup file path.sql>
- Deploy your code to heroku
- heroku run python manage.py migrate
- heroku run python manage.py createsuperuser 
- restore data 
         heroku pg:psql --app <application name>  <  <backup file path.sql>

Regards,
Ketan

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAA%3Diw__mSiZvrTZTrraLB4jq-kiFvm7Qkr0B6D%2Bffa2w4J-rkg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Joel Mathew

unread,
Dec 18, 2018, 10:50:15 AM12/18/18
to django...@googlegroups.com
Hi, thank you for responding. My issue was because there was an autogenerated database, and another that I had created. When I ran the local dev server, for some reason, it used the one I created. However on Heroku, ir was using the autogenerated database. Once I deleted the auto generated database, the problem went away.

Sincerely yours,

 Joel G Mathew



Reply all
Reply to author
Forward
0 new messages