Connecting postgres DB with heroku - django

During development, I used postgres DB where I had to pip install psycopg2. Most of my post I updated during the course of development was on postgres DB. Now during deployment, I discovered that a part of the installation when I did heroku push master is installing sqlite. Now my problem is, how can I deploy my postgres DB for development in heroku, knowing that most of my post on development are really important.. thanks

Related

Django migration error in heroku postgres

I've just deployed my Django website on Heroku and while running the command to make migrations it shows a lot of migrations to apply but when I try to migrate it, it says no migrations to apply.
Here's a photo of it.

makemigrations or migrate while server is runnig

I'm wondering how we can handle database migration in django while the site in production as while developing we stop the server then make changes in database then rerun the server I think it may be stupid question but I am learning by myself and can't figure it out thanks in advance.
You can connect to the server using ssh and run commands to migrate without stopping the server and once you are done, you restart the server.
python manage.py makemigrations
and then
python manage.py migrate
and then restart the server.
for example: in case of nginx and gunicorn
sudo service gunicorn restart
sudo service nginx restart

Run manage.py migrate but no accout related tables created in graphite.db

I'm installing graphite 0.9.15 on Ubuntu Server 16.04 LTS.
During configuration step
cd /opt/graphite/webapp/graphite
sudo cp local_settings.py.example local_settings.py
Then using the command in the official installation instruction:
sudo PYTHONPATH=/opt/graphite/webapp/ python manage.py migrate --settings=local_settings
Gave information
Operations to perform:
Apply all migrations: (none)
Running migrations:
No migrations to apply.
Then I went to check the graphite.db
sqlite3 graphite.db
SELECT name FROM sqlite_master WHERE type='table';
Only two tables created, django_migrations and sqlite_sequence, no account relevant tables. And inside apache error log, /opt/graphite/storage/log/webapp/error.log, OperationalError: no such talbe: auth_user. It's because of missing those account tables.
Some info:
ubuntu 16.04 LTS
python2.7.11
django 1.9.6
django-tagging 0.4.3
whisper, carbon, graphite 0.9.15
Please who know the reason and how to solve this? Thanks a lot!
Actually my issue is that when I run "sudo python manage.py migrate" each time only partial tables are created and several tables name starts with account_, dashboard_, events, always miss.
Finally found the reason, don't use that command I used and which mentioned in official doc. It does not work on Django 1.9 and above. And graphite official document have not been updated for long time ....
What you need is
sudo PYTHONPATH=/opt/graphite/webapp django-admin.py migrate --settings=graphite.settings --run-syncdb
You have to include graphite in the INSTALLED_APPS in the Django settings.py file.

Is it mandatory to activate virtual environment before deploying django apps on heroku?

I am trying to deploy a django website project with 3 apps on heroku. In the heroku website it is mentioned to activate virtual environment before deploying apps. But the venv file is taking a lot of space (actually it is taking the 50% of the space of my project) and deploying it is taking a lot of time. I hope for a nice answer. :)
Whether you use a virtualenv in your local development is up to you, but in either case you'll have to specify a requirements.txt file so Heroku knows what Python packages/dependencies to install.
Creating a minimal requirements.txt is very easy using a virtualenv, as outlined in Heroku's tutorial for Django.
pip freeze > requirements.txt

Deploy ready Django application on Heroku servers

I have already developed an application with Python Django and it's working, I am new to Python Django and now I need to deploy it on heroku servers, there are so many blogs and websites including heroku site that explains deploying a django app on heroku from scratch I haven't found any which talks about a running app
for example all of them need installing django which makes me confused,
this is the folder structure of my app:
myapp
|_my_app
| |_Settingd.py
| |_urls.py
| |_wsgi.py
|__webapp
|_statics(folder)
|_admin.py
|_models.py
|_views.py
The app is connecting to mysql server locally
Question(s):
Now I am totally confused, how do I have to deploy my running app on heroku? among the steps to deploy an app on heroku provided below which ones are mandatory for me and which ones I can escape and according to my folder structure where should be the location of requirements.txt or Procfile and what should be the content of them?
https://devcenter.heroku.com/articles/getting-started-with-django
Do I have to install virtualenv? and yes where should I run this command(in which folder)
I think I don't have to install django or any database api or driver for django? since they are all already installed
So the first question of yours is why the app should be running inside Virtualenv?
what's the first step? Install Django, right? Not quite. One common problem with installing packages directly to your current site-packages area is that, if you have more than one project or use Python on your machine for things other than Django, you may run into dependency issues between your applications and the installed packages. For this reason, we'll be using virtualenv to manage our Django installation. This is common, and recommended, practice among Python and Django users.
Then install and activate your virtualenv using this command...
$ virtualenv env
$ source env/bin/activate
And finally we activated the environment. Now it'll look like this
(env)rs#rajasimon-desktop:~/studio/Project$
Then i guess your second doubt what is the purpose to install django-toolbelt ?
If you are installing django-toolbelt it will install all the dependencies or package need.
it contains Django, psycopg2, gunicorn, dj-database-url, dj-static, static
Firstly Heroku natively uses postgres. Life will be easier for you if you use that locally.
If you really want to use mysql, you have two paths to follow.
1) Run mysql locally, but convert to postgres when migrating to Heroku using the mysql2psql gem, as described here: https://devcenter.heroku.com/articles/heroku-mysql
2) Use a mysql addon like https://addons.heroku.com/cleardb
However my recommendation would be to use postgres end to end, as it is baked into Heroku, and you'll be working with the default ways of using Heroku, not against the
This is my project package i am currenlty working
(env)ri#rajasimon-desktop:~/studio/project$ pip freeze
Django==1.6.5
MySQL-python==1.2.5
Pillow==2.5.3
argparse==1.2.1
django-ckeditor-updated==4.2.8
wsgiref==0.1.2
where should be the location of requirements.txt & Procfile ?
How to make requirements.txt file ?
By running below command will automatically include all packages inside txt file.
pip freeze > requirements.txt
Declare process type with Procfile
The procfile is for starting the dyno when in productioin. I always right like this..
web: gunicorn project.wsgi
So finally your project structure will look like this
myapp
|_my_app
| |_Settingd.py
| |_urls.py
| |_wsgi.py
|__webapp
| |_statics(folder)
| |_admin.py
| |_models.py
| |_views.py
|__manage.py
|__requirements.txt
|__Procfile