I have created django project with postgres database I have deployed my project into heroku server, and also migrate with
heroku run python manage.py migrate
I want to push my stored database to heroku database,
PGUSER=edpuser PASSWORD=1qazxsw2 heroku pg:push applications postgresql-curly-07168 --app application
but getting
> error shiv#shiv:~/Documents/projects/django_related_project/zoedp$
> heroku pg:push applications postgresql-curly-07168 --app application
> heroku-cli: Pushing applications ---> postgresql-curly-07168 ▸
> Remote database is not empty. Please create a new database or use
> heroku pg:reset
I also run command heroku pg:reset and again try again
this time I got error
shiv#shiv:~/Documents/projects/django_related_project/zoedp$ PGUSER=edpuser PASSWORD=1qazxsw2 heroku pg:push applications postgresql-curly-07168 --app application
heroku-cli: Pushing edpapplication ---> postgresql-curly-07168
pg_dump: [archiver (db)] connection to database "application" failed: FATAL: Peer authentication failed for user "edpuser"
pg_restore: [custom archiver] could not read from input file: end of file
▸ pg_dump errored with 1
here is my setting.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'applications',
'USER': 'edpuser',
'PASSWORD': '1qazxsw2',
'HOST': 'localhost',
'PORT': '5432',
'ATOMIC_REQUESTS': True
}
}
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=600)
DATABASES['default'].update(db_from_env)
and overwriting pg_hba.conf deny me.
what should I do?
I was having this issue, is more related to postgresql auth configuration rather than heroku pg:push command
I would recommend this approach:
Set a password for the postgres user:
Based on this amazing answer: https://stackoverflow.com/a/26735105/3172310
At this moment:
You have set a password for the postgres user and configure postgres to ask for id when using psql, which seems pg command does.
then run command as this:
PGUSER=postgres PASSWORD=pg_password heroku pg:push local_db_name DATABASE_URL --app application_name
Replacing:
pg_password: password for the postgres user
local_db_name: your local database
application_name: heroku app name
and should work fine!
Related
I'm having a problem with running unit tests in django while using ElephantSQL,
when running command python manage.py runserver everything works just fine,
I'm able to connect to the server without any problem
but when running the command python manage.py test
I'm getting this error below:
C:\Users\Sman9\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\siteid running initialization queries against the production database when it's not needed (for example, when running tests). Djang
warnings.warn(
Got an error creating the test database: permission denied to create database
Creating test database for alias 'default'...
C:\Users\Sman9\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\db\backends\postgresql\base.py:323: RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against the production database when it's not needed (for example, when running
tests). Django was unable to create a connection to the 'postgres' database and will use the first PostgreSQL database instead.
warnings.warn(
Got an error creating the test database: permission denied to create database```
my databases setting in settings.py file
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '####',
'USER': '#####',
'PASSWORD': '#############',
'HOST': 'chunee.db.elephantsql.com',
'PORT':'',
}
}
}
Make sure that you have granted all required privileges to a user you have created for managing your database.
Using psql you can do so with the following command:
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
Additionally, you ought to have psycopg2 installed for the postgres DB to pair with Django.
In a terminal execute the following:
pip install psycopg2
I am having trouble migrating my development database onto Heroku. This is for a personal project written in Django.
settings.py
db_from_env = dj_database_url.config()
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
DATABASES['default'].update(db_from_env)
I've migrated the database locally and pushed the migration onto Heroku already. Then, I ran the heroku run python manage.py migrate command to migrate the database on Heroku.
I had accidentally ran makemigrations on Heroku, but have restarted my dynos since.
Currently, my database on Heroku is not populated at all.
I have a Django app on Heroku, I'm trying to connect that app to a Microsoft azure mySQL database. but the following error while in the Heroku BASH terminal when trying to create a superuser of migrating appears.
django.db.utils.OperationalError: (1044, "access denied for user 'azure username' to database 'azure db name'")
where azure username and azure db name are my personal corresponding database parameters that i've created through Microsoft's portal
my password is correct i've double checked it.
this is my production settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'azure db name',
'USER': 'azure username',
'PASSWORD': '',
'HOST': 'eu-cdbr-azure-north-e.cloudapp.net',
'PORT': '3306'
}
}
is there an extra parameter that i need to enter for validation? or an extra package that i need to install?
this is requirements.txt
appdirs==1.4.0
dj-database-url==0.4.2
Django==1.10.2
gunicorn==19.6.0
packaging==16.8
pyparsing==2.1.10
six==1.10.0
MySQL-python==1.2.5
mysqlclient==1.3.9
Thanks
So i used postgres in development for my django project and have important entries in there and i want to deploy to my app in heroku
is there a simple way to do this?
Sure. You just need to export your local database and import it on the Heroku Postgres database. Heroku has a guide to do just that.
Create a dump from your local database. PGPASSWORD=mypassword pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump
Upload mydb.dump somewhere Heroku can access it.
Import to heroku. heroku pg:backups restore 'https://s3.amazonaws.com/me/items/3H0q/mydb.dump' DATABASE_URL
Source
I am trying to link a Heroku Postgres databse with my Django application. I have created the database and linked it to my Heroku application using this tutorial. I can't seem to get it working with Django, however.
I am able to access the database through the heroku pg:psql command. But when I try to run python manage.py migrate, Django gives...
settings.DATABASES is improperly configured
Please supply the ENGINE value.
In settings.py, I have...
import dj_database_url
DATABASES = {
'default': dj_database_url.config(default=os.getenv('DATABASE_URL'))
}
I have already promoted the correct heroku postgres database to my app's DATABASE_URL variable, which I can verify through heroku config.
You've misread the instructions. It should be:
DATABASES = {
'default': dj_database_url.config()
}
dj_database_url already parses the env var, you don't need to pass it explicitly.
Heroku config variables aren't available in Django settings.py when testing locally.
https://stackoverflow.com/a/21763381/3783608