Django shell writes record in wrong db - django

There are two projects in our server: the first project is test project,
the second project is not test project. All projects uses mssql db. The first project uses test db, the second project uses db that is not test. The first project reads environment variables from .env file. The second project reads environment variables from .bash_profile. When I ran django shell in the first project and created record using sql query record was created in db that is not test. How could this happen?

Related

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.

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.

Export/Import Django project settings in PyCharm

Actually I have project with about 20 settings (Django server, Django tests, fabric tasks). Now I want to move my environment to other computer.
Is it possible to migrate all these configurations or should I create manually one by one in new PyCharm instance?
Yes there is. What you need to do, is copy everything in your project directory, including .idea folder, and pasting it to the new place that you want to place it.
Now, all you have to do is open the directory as a project using PyCharm in your new workstation.