I configured a postgressql database on ec2 instance. Now I want to talk to this database server using a different ec2 instance which is running a python/django framework.
My settings.py file contains:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ['DB_NAME'],
'USER': os.environ['DB_USERNAME'],
'PASSWORD': os.environ['DB_PASSWORD'],
'HOST': os.environ['DB_HOSTNAME'],
'PORT': os.environ['DB_PORT'],
}
}
Where "DB_NAME" and other variables are defined in .ebextensions/*.config file under option_settings. When I push the code to AWS, the deployment log files shows that DB_NAME does not exists. I am not sure where I am going wrong. The Elasticbeanstalk console shows the variables though.
Related
I replaced all URLFields in the models with Cloudinary fields, and decided to drop the DB and make new, because issues appeared. So every migration file, accept init files was deleted, I dropped the DB, even deleted all containers and volumes(I use docker for PostgreSQL). I have made new images and containers in docker. New database. But still can't connect to database nad migrate.
This is the error:
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more det ails.
This is my DB Settings:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'fishbook_db', 'USER': '*******', 'PASSWORD': '********', 'HOST': 'localhost', 'PORT': '5432', }, }
I have tried to fix the problem, by searching for this error in the web. I see a lot of people have the same problem, but I wasn't able to find solution so far.
Currently , I have deployed my django project on google app engine. I need to run python manage.py migrate command so that auth_user table should be created on my google cloud instance . But don't know where to run this command.
If I get it right, your app runs on App Engine (sandboxed environment) and uses Cloud SQL.
1) Configure your database in settings.py as you can see below.
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
# Running on production App Engine, so use a Google Cloud SQL database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/project-id:instance-name',
'NAME': 'database-name',
'USER': 'root',
}
}
elif os.getenv('SETTINGS_MODE') == 'prod':
# Running in development, but want to access the Google Cloud SQL instance in production.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'INSTANCE': 'cloud-sql-instance-ip-address',
'NAME': 'database-name',
'USER': 'root',
'PASSWORD': 'password',
}
}
else:
# Running in development, so use a local MySQL database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'database-name',
'USER': 'username',
'PASSWORD': 'password',
}
}
2) Set environment variable SETTINGS_MODE to prod (or do not set if you want to access your local MySQL server).
3) Run the below command from your machine.
$ SETTINGS_MODE=prod python manage.py migrate
You can find more details in App Engine documentation - Management commands and Alternate development database and settings.
My app engine app is doing well, but I want to toggle the "only allow secure connections" option in the Cloud SQL configuration. When i do so, I can still connect remotely and in local development. However, my deployed app stops working with a 1045 error "access denied"
I cannot figure out where to store/upload the ssl certificates on the deployed app or how to call them from settings.py
Can someone please help?
Here is the relevant section of settings.py (redacted)
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
# Running on production App Engine, so use a Google Cloud SQL database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/<myappengineapp>:<mycloudsqlinstance>',
'NAME': 'test',
'USER': 'root',
'PASSWORD': '<mypassword>',
'OPTIONS':
<ssl goes in here?>
}
}
else:
# Running in development, but want to access the Google Cloud SQL instance
Is there a step that I missed, perhaps a "syncdb" step for Google Cloud SQL? I read both of these:
Using Google Cloud SQL
Django Support
My application has access to Google Cloud SQL but I think I just have to create the tables in Google Cloud SQL. What's the command to do that? Maybe that will fix it. Running python manage.py syncdb updates SQL on localhost but I'd like to update the database on Google Cloud SQl.
EDIT: Below are the Google Cloud SQL settings and the settings.py for my project.
There are three type of connections:
1) your dev machine to your local mysql instance (Easy!)
2) your app engine instance (in Google Cloud) to Google Cloud SQL instance (the same way described in the document)
3) your dev machine to cloudsql instance (Hard): the encouraged way is to obtain an static IP (for a while that doesn't cost you much money), and use the IP to connect cloudsql instance.
Django code [3] should allow you switch between above cases. The command [1] allows you to syncdb to cloudsql instance. If you want your django model to manipulate data in cloudsql instance, you can add config [2] to app.yaml
[1]
SETTING_MODE=prod ./manage.py syncdb
[2]
env_variables:
SETTINGS_MODE: prod
[3]
import os
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
# Running on production App Engine, so use a Google Cloud SQL database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/your-project-id:your-instance-name',
'NAME': 'django_test',
'USER': 'root',
}
}
elif os.getenv('SETTINGS_MODE') == 'prod':
# Running in development, but want to access the Google Cloud SQL instance
# in production.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': 'static-ip-of-cloudsql-instance',
'PORT': '3306',
'NAME': 'django_test',
'USER': 'username',
'PASSWORD': 'password'
}
}
else:
# Running in development, so use a local MySQL database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_test',
'USER': 'root',
'PASSWORD': 'root',
}
}
I want to set database setting in django project.
Which settings.py I should use.
I found many settings.py file.
I have setup devstack where many folders are there like horizon, cinder, nova etc.
I found settings.py in horizon folder.
and from when I setup Django I found in /usr/local/lib/python2.7/dist-packages/django/conf/project_template/project_name folder.
Please make suggest which settings.py I should use and
I can access database by user root with no database name giving in MySql Workbench.
Which database connection I should use?
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'nova',
'USER': 'root',
'PASSWORD': 'password',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
Please help..
You have to setup your DB in the settings.py file in horizon/openstack_dashboard folder .The DB name is devstack or any other name .All the django apps table will be created in a single DB