I'm not able to connect proxy host database in Django - django

after running
python manage.py runserver
Got the Error port 5432 failed: FATAL: Feature not supported: RDS Proxy currently doesn’t support command-line options.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'DATABASE_NAME',
'USER': 'DATABASE_USER'
'PASSWORD': 'DATABASE_PASSWORD'
'HOST': 'PROXY_HOST',
'PORT': '5432',
'OPTIONS': {
'options': f"-c search_path={DATABASE_SCHEMA}"
},
}
}
After commented OPTIONS -- {DATABASE_SCHEMA}
models already migrated in particular schema but schema is not detected.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'DATABASE_NAME',
'USER': 'DATABASE_USER'
'PASSWORD': 'DATABASE_PASSWORD'
'HOST': 'PROXY_HOST',
'PORT': '5432',
# 'OPTIONS': {
# 'options': f"-c search_path={DATABASE_SCHEMA}"
# },
}
}
so finally getting migrations error because it's pointing to the database not particular schema
You have 178 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): **address, analytics, etc...**
Run 'python manage.py migrate' to apply them.
February 09, 2023 - 15:42:20
Django version 3.2.9, using settings 'MoreProjectAPI.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
it's not connected my schema could any one please suggest how can i fix this issue in root level not in every model level.

hi your server output after commenting looks fine, try migrating first as it suggests!
python manage.py migrate
or
python3 manage.py migrate
or simply
./manage.py migrate
and then run your server

Related

Django: Peer authentication failed for user

I've already a functioning website that use sqlite3 but I prefer to restart my website project with an empty project that immediately use PostgreSQL/PostGIS. At the end of the configuration of settings.py I will make a dump for upload all the sqlite3 tables into the new DB. Nobody models of the old project will modify into this new project. The differece between the old and the new project is only the DBMS.
This is settings.py:
INSTALLED_APPS = [
...
'django.contrib.gis',
]
...
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'my_project_name',
'USER': 'db_user',
'PASSWORD': 'password_of_db_user',
}
}
After this I've tried to test the server with python3 manage.py runserver but I see this error message:
django.db.utils.OperationalError: FATAL: Peer authentication failed
for user "db_user"
I'm sure that NAME, USER and PASSWORD are correct, the db is in localhost. I've created, a couple of week ago, another simple project to learn GeoDjango with this same settings and that website run fine.
Looks like you're missing the host field in your config:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'my_project_name',
'USER': 'db_user',
'PASSWORD': 'password_of_db_user',
'HOST': 'localhost' # missing part
}
}

How to migrate to Postgresql?

My Django project on Heroku I want to migrate from SQLite to PostgreSQL. I changed my settings.py to PostgreSQL. On Windows I installed PostgreSQL and psycopg2. I created the database manually.
As I run makemigrations it creates an SQLite database. Why?
After you have run python manage.py makemigrations you need to run python manage.py migrate to apply the data to the new database.
#Dacey you'll need to edit the settings.py file and change the database name (and potentially connection).
Database
https://docs.djangoproject.com/en/4.1/ref/settings/#databases
''' here you use triple quotes to block out your original statement
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'old_sqlite.db',
} }
close your triple quotes '''
Change the above to something like this
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'PostGres_New',
'USER': 'postgres',
'PASSWORD': 'postgres',
'PORT':'5432',
'HOST':'localhost',
} }

Sync database content with django

We have a local sqlite3 and an online mariaDB database and want to sync the content within django 1.10.3.
The settings are:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'online_database',
'USER': 'xxx',
'PASSWORD': 'xxxxx',
'HOST': 'xxx.xxx.xxx.xxx',
},
'local':{
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'local_database'
}
}
With python manage.py migrate --database=local we were able to sync all the model structures but additionally we are interested in syncing the content of the tables. Is there anything implemented in django?
Maybe you can do it using fixtures. Use the following:
python manage.py dumpdata --database online_database <other parameters> > fixture.json
python manage.py loaddata --database local_database <other parameters> path/to/your/fixtures/fixture.json

Django 1.8 migrating local postgres database into a heroku database

I've been stuck on this part for a while.After completing all the other steps when I enter git push heroku master, it pushes all the files but how do I migrate my local database? There are no commands for that. My settings.py file is still pointing to the local postgres database.How do I migrate this data into the heroku database?
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'music',
'USER': '**',
'PASSWORD': '**',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
Did you followed the heroku django tutorial. From the django-settings they are clearly mention how heroku will detect database url using dj-database-url package.
So just define this setting below your settings.py file then you are good to go.
For Importing and Exporting to heroku postgres please see this heroku-postgres-import-export

django.db.utils.OperationalError: FATAL: database "Path" doesn't exist

I'm newbie with python and django,
Im trying to setting up Django in windows7,
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.path.join(BASE_DIR, 'amour'),
'USER': 'openpg',
'PASSWORD': 'openpgpwd',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
when trying to execute the server: python manage.py runserver
the below error appear :django.db.utils.OperationalError: FATAL: database "Path" doesn't exist
I already install PostgreSql 9.3 and Python 2.7.
You should pass the name of the database, not the filename. So if you created database named "amour" then setting will be:
DATABASES = {
'default': {
...
'NAME': 'amour',
...
}
}