Django PostgreSQL setting with separated credential file? - django

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.

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.

How to store postgresql database in django - project folder?

Where is postgreSQL database saved in a django folder (that which has manage.py)?
If not, I presume it must be stored in postgres folder of root directory.
Then, how to transfer this file to those systems having no postgres installed, so that when they run server, they can see seamlessly all the data/app?
Can we ask DJANGO to create the database file in its project folder itself and does this help in such transfers? Thanks.

How to decouple local directory and Heroku project

I am developing an app with Django and I successfully pushed it on Heroku.
This app has a postgres database and a form to allow users to fill the database.
I have coupled the local directory and Heroku, so that both if I run the server by command prompt, or if I access the app, and submit the form, my database get changed.
Now I want to make some experiments on the local database without changing the one on Heroku.
Is it possible?
Can I do it by just commenting the database URL in settings.py ?
I have searched for this matter on Google but I don't know the name it, so that I cound not find proper answer.
This is not a question of "decoupling" directories. It is because you are trying to use sqlite on Heroku, and you have added the sqlite file to your git repo.
You cannot use sqlite on Heroku; use the postgres add-on. Additionally, your sqlite file must not be in source control.

Is there a way to share local PostgreSQL between computers?

I recently started working on some project with my friends. I'm working on backend with Django, and others do frontend. As they have no knowledge about Django, I was wondering if I can add the db file into the project folder, so that they can use the local db by just pulling the db file from Github repository.
When I used to use sqlite3, I could do this simply having the sqlite3.db file in my project folder. However, PostgreSQL has me use its program to create database, I'm confused how I can get the db file.
Is it possible to have a local PostgreSQL db file in my Django project so that my friends use the db by just cloning the project and installing PostgreSQL in their computers?
Just so you know, I created my Django project with cookiecutter-django.

How can you access your online postgresql database when developing on your local machine?

I want to start developing a django app on heroku which uses the postgresql database. I already got my hello world django app working on heroku, but now I am wondering how to develop with the postgresql database.
How do people do this? Can I link to the heroku postgresql database in the settings.py and develop on my local 'django runserver' server?
How do people do this? Do they use a postgresql database on their own machine? How would you keep the online one and your local one the same?
I think one of the best way - it is to copy database to your local machine, but it will be hard, if you have got huge database.
You can also use working database from remote server. Just type ip/host and other settings for database on your server and you'll get access.
Not sure about python and how you interact with heroku (do you use the heroku cli??) but in the Ruby land we can do heroku db:pull which will pull the DB from heroku and magically transpose it into whatever DB you use locally, the same for pushes. It also supports individual/combintations of tables to push/pull.