Postgresql migration (from local machine to digital ocean) - django

I want to move my local Postgresql database (preloaded with data) into my digitalocean droplet.
2 challenges I'm facing:
the /data/base/25760 is the folder with my data, do I SCP this directly into Digital Ocean Root/home/django/django-project?
How do I link the database to the droplet using the settings.py file? I'm getting errors: FATAL: password authentication failed for user "root"
From my search, it looks like users are not advised to load their local databases directly into their VPS, maybe I'm wrong about this.
thanks very much!

Related

Heroku: installing Postgres without local db | Django

I've already pushed my Django files to Heroku via Git and now I'd like to configure at Heroku server the Postgres database. After that, I need to transfer my local sqlite database to Heroku Postgres.
All of this issue is because I don't have admin rights on my local PC (corporate unit) to install Postgres.
So basically:
1. Configure remotely Postegres at Heroku;
2. Migrate local database (sqlite) to Heroku (Postgres).
I don't know if there is another path to go on...
Thank you!
That's some crazy gymnastics you're trying to do. Getting a grasp of PostgreSQL setup is hard as it is. There are several user/table privileges you have to maintain. Sqlite3 has very simple settings in the settings.py file in Django, while Postgres requires a username, password, Host, and Port.
Also the sql you export from sqlite3, might not ingest directly into the PostgreSQL. See this. You'll have to install Postgres on your local machine, if you plan to have any sort of ok workflow as far as I can see. You can probably explore docker to create a local dev environment on your corporate PC.

View data on PostgreSQL database in Ubuntu

I am running a Django based website on a Digital Ocean Ubuntu droplet, using PostgreSQL. The site is running and data is being stored in the database successfully.
How do I view the data in the database? I was able to do this easily using PGadmin on my windows machine before I pushed it to production. How do I do this now that there is no GUI?
Can I still use PGadmin somehow and "remote" into my droplet?
Thanks!

Django Cookiecutter Production Server Setup on DigitalOcean

I am trying to setup my Django Cookiecutter code on an Ubuntu server hosted on Digital Ocean. (My first attempt at such a thing.)
It does not appear that my .env file is loading?
DATABASE_URL=postgres://myapp:pwd123#127.0.0.1:5432/myapp
DJANGO_ALLOWED_HOSTS=187.99.73.187,myapp.com,187.99.73.187:8000
DJANGO_ADMIN_URL=admin
DJANGO_SETTINGS_MODULE=config.settings.production
DJANGO_SECRET_KEY=A8fpfkN5}...m5~^jggSo3wq`0Z*
I am using the latest version of Cookiecutter. https://github.com/pydanny/cookiecutter-django
Do I have to do something special to activate/recognize this code?
Right now I am getting an error of add '187.99.73.187' to ALLOWED_HOSTS. But it is in the env file.
I also had Postgres error based on not getting data from this new .env file.
I see instructions and videos for setting up Cookiecutter on Docker, Heroku and PythonAnywhere. Just not for a simple Linux installation.
Thanks.

Django PostgreSQL setting with separated credential file?

I want to migrate my django's database from MySQL to PostgreSQL.
Previously I've used database configuration options just like this example from Django website.
The MySQL engine on database setting has options: 'read_default_file', so I can separate my database credential on external file.
Now I'm ready to switch to PostgreSQL with psycopg2 engine, but I can't find the similar options like read_default_file.
Is there any solution for this?
Or may be I should change to other database engine of PostgreSQL which has this options? Thanks
read_default_file is purely a mysql thing. It cannot be used for postgresql. The closest equivalent in postgresql is the .pgpass file which is a file that needs to be created in the home directory of the user running the psql client. That defines the user's password.
When you are using django in development creating a file in your your home directory would do the trick. But in production you are not supposed to run the django dev server. Production WSGI servers run under restricted user accounts that may not have a home directory. In that case you need to use the PGPASSFILE environment variable to tell django where to look for the password.

Django on Vagrant, Postgres both locally and on Heroku, could not connect to server: No such file or directory

I finally got my Django app to deploy on Heroku, using Vagrant and Postgres for both local and production. The localhost is up and running, and I'm in the admin, adding users. But when I run
heroku run python manage.py syncdb
it barfs up this error:
psycopg2.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Same thing happens when I try to access the admin online: http://vast-sierra-7949.herokuapp.com/admin/
I'm new to Heroku, and I've tried just about every getting started tutorial I could find, including
http://gettingstartedwithdjango.com/en/lessons/introduction-and-launch/
https://devcenter.heroku.com/articles/django,
https://github.com/callmephilip/django-heroku-bootstrap, and
https://github.com/jpadilla/django-project-template
This last github link actually allowed me to deploy, before I was just getting an error when I ran
git push heroku master
and that error was: manage.py: error: no such option: --noreload
I know there are several posts with this error, but I've looked through as many as I could find with no luck on resolving the issue.
Thank you in advance,
Anthony
Be sure to setup heroku DB settings
Check out this blog post: http://jamie.ideasasylum.com/2012/09/connecting-navicat-to-postgresql-on-vagrant/
The author talks about how you have to modify pg_hba.conf by adding the following lines to allow a host machine (in this case, you Heroku instance) to connect to a postgres server installed on a guest VM within the host.
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 10.0.2.2/32 md5
I'm not sure if you can access these files on a Heroku instance, but it's a place to start. Good luck!