I want to migrate my site from a First to a Second Generation Cloud SQL instance, this is the old config:
DATABASES['[DATABASE_NAME]'] = {
'ENGINE': 'google.appengine.ext.django.backends.rdbms',
'INSTANCE': '[PROJECT_ID]:[INSTANCE_ID_1stGEN]',
'NAME': '[DATABASE_NAME]',
'USER': [MY_USER],
'PASSWORD': [MY_PASSWORD],
}
This works fine, now I'm trying with this code:
DATABASES['[DATABASE_NAME]'] = {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/[PROJECT_NAME]:[REGION]:[INSTANCE_ID]',
'NAME': '[DATABASE_NAME]',
'USER': [MY_USER],
'PASSWORD': [MY_PASSWORD]
}
And this code
DATABASES['[DATABASE_NAME]'] = { # 2da gen no funciono error COUNT_ROWS
'ENGINE': 'django.db.backends.mysql',
'HOST': '[PROJECT_ID]:[REGION]:[INSTANCE_ID]',
'NAME': '[DATABASE_NAME]',
'USER': [MY_USER],
'PASSWORD': [MY_PASSWORD]
}
And this is the error:
AttributeError at /
'module' object has no attribute 'FOUND_ROWS'
/base/alloc/tmpfs/dynamic_runtimes/python27g/79cfdbb680326abd/python27/python27_lib/versions/third_party/django-1.5/django/db/backends/mysql/base.py in _cursor
kwargs['client_flag'] = CLIENT.FOUND_ROWS
I need your help, please.
The Django version is 1.5 is very old
I found a error, the ENGINE is wrong, I replaced it with google.appengine.ext.django.backends.rdbms:
DATABASES['[DATABASE_NAME]'] = {
'ENGINE': 'google.appengine.ext.django.backends.rdbms',
'HOST': '/cloudsql/[PROJECT_ID]:[REGION]:[INSTANCE_ID]',
'NAME': '[DATABASE_NAME]',
'USER': [MY_USER],
'PASSWORD': [MY_PASSWORD]
}
but it still fails, now it says that an INSTANCE key is needed, then I replace HOST by INSTANCE:
DATABASES['[DATABASE_NAME]'] = {
'ENGINE': 'google.appengine.ext.django.backends.rdbms',
'INSTANCE': '/cloudsql/[PROJECT_ID]:[REGION]:[INSTANCE_ID]',
'NAME': '[DATABASE_NAME]',
'USER': [MY_USER],
'PASSWORD': [MY_PASSWORD]
}
... nothing ...
DATABASES['[DATABASE_NAME]'] = {
'ENGINE': 'google.appengine.ext.django.backends.rdbms',
'INSTANCE': '[PROJECT_ID]:[REGION]:[INSTANCE_ID]',
'NAME': '[DATABASE_NAME]',
'USER': MY_USER,
'PASSWORD':MY_PASSWORD
}
trying this, and now another error:
InternalError at /
(0, u'Not authorized to access instance: [PROJECT_ID]:[REGION]:[INSTANCE_ID]')
/base/alloc/tmpfs/dynamic_runtimes/python27g/79cfdbb680326abd/python27/python27_lib/versions/1/google/storage/speckle/python/api/rdbms.py in MakeRequest
request.request_id = self._idempotent_request_id
response = self._MakeRetriableRequest(stub_method, request)
else:
response = self.MakeRequestImpl(stub_method, request)
if (hasattr(response, 'sql_exception') and
response.HasField('sql_exception')):
raise _ToDbApiException(response.sql_exception) ...
return response
def _MakeRetriableRequest(self, stub_method, request):
"""Makes a retriable request.
Adding SSL/TSL configuration:
DATABASES['[DATABASE_NAME]'] = {
'ENGINE': 'google.appengine.ext.django.backends.rdbms',
'INSTANCE': '[PROJECT_ID]:[REGION]:[INSTANCE_ID]',
'NAME': '[DATABASE_NAME]',
'USER': [MY_USER],
'PASSWORD': [MY_PASSWORD],
'OPTIONS': {'ssl': {
'key': '/servidor/[INSTANCE_ID]/client-key.pem',
'cert': '/servidor/[INSTANCE_ID]/client-cert.pem',
'ca': '/servidor/[INSTANCE_ID]/client-ca.pem',
}}
And I still get the same error.
The certificate is working, with MySQL Workbench there is no problem.
The rdbms library will not work with an upgraded Second Generation Cloud SQL instance as stated on the documentation. In order to connect to your Sencond Generation Cloud SQL instance to your App Engine Standard application please make sure that your service account has the correct permissions and use the Unix domain socket. All the relevant information can be found here.
Related
I am trying to connect Django to the PostgreSQL database, but this is my first time doing it, so I am not sure how exactly to do it. The problem seems to be with the line, where the password is.
settings.py -
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<db_name>',
'USER': '<db_username>',
'PASSWORD: '<password>',
'HOST': 'db_hostname_or_ip>',
'PORT': 'db_port',
}
}
When I try to make migrations in my prompt, (python manage.py makemigrations) I am getting the error mentioned in the title. Can anybody help me please?
Your code
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<db_name>',
'USER': '<db_username>',
'PASSWORD: '<password>',
'HOST': 'db_hostname_or_ip>',
'PORT': 'db_port',
}
}
What it actually should be
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<db_name>',
'USER': '<db_username>',
'PASSWORD': '<password>',
'HOST': 'db_hostname_or_ip>',
'PORT': 'db_port',
}
}
Actually you're forgetting the closing qoute after PASSWORD
Im facing issue while connecting to oracle db in django project,
Oracle connection details:
'''
XXXX=
(DESCRIPTION =
(LOAD_BALANCE = YES)
(FAILOVER = YES)
(ADDRESS_LIST =
(ADDRESS = (COMMUNITY = XXX.xxxx)
(PROTOCOL = TCP)
(Host = xxx-xx.xxx.com)(Port = 1521)))
(CONNECT_DATA =
(service_name = xxxx.xxxxx)))
'''
i want to fit oracle details in below django database connection code,
'''
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'xe',
'USER': 'a_user',
'PASSWORD': 'a_password',
'HOST': 'dbprod01ned.mycompany.com',
'PORT': '1540',
}
}
'''
Welcome to StackOverflow!
From the Doc. If tnsnames.ora isn't being used.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': '(DESCRIPTION=(LOAD_BALANCE=YES)(FAILOVER=YES)(ADDRESS_LIST=(ADDRESS=(COMMUNITY=XXX.xxxx)(PROTOCOL=TCP)(Host=xxx-xx.xxx.com)(Port=1521)))(CONNECT_DATA=(service_name=xxxx.xxxxx)))',
'USER': 'a_user',
'PASSWORD': 'a_password',
'HOST': '',
'PORT': '',
}
}
Or you have made sure your oracle client has tnsnames configured
tnsnames.ora
MY_AWESOME_TNS_ALIAS=(DESCRIPTION=(LOAD_BALANCE=YES)(FAILOVER=YES)(ADDRESS_LIST=(ADDRESS=(COMMUNITY=XXX.xxxx)(PROTOCOL=TCP)(Host=xxx-xx.xxx.com)(Port=1521)))(CONNECT_DATA=(service_name=xxxx.xxxxx)))
Now django can be configured by alias name. You hide the connection-details from the django application.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'MY_AWESOME_TNS_ALIAS',
'USER': 'a_user',
'PASSWORD': 'a_password',
'HOST': '',
'PORT': '',
}
}
Best of luck!
I have different database other than default.
#receiver(post_save, sender=Customer)
def customer_post_save_task(sender, instance, created, **kwargs):
print("hmm", created)
But This only triggers when Customer is created from default db
If Customer is created from another db it does not get invoked.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'mydb': {
'ENGINE': 'django.contrib.gis.db.backends.mysql',
'NAME': 'mydb',
'USER': 'root',
'PASSWORD': 'test',
'HOST': 'localhost',
'PORT': '3306',
}
When customer is created in mydb signal doesnot trigger. What can I do?
My database and project work great using this database setting:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'myprojectdb',
'USER': 'myprojectuser',
'PASSWORD': 'my_secret_password',
'HOST': 'localhost',
'PORT': '5432',
'ATOMIC_REQUESTS': True
},
}
But I want to add a 'readonly' database entry for my readonly db user, like this, so that I can run django-sql-explorer:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'myprojectdb',
'USER': 'myprojectuser',
'PASSWORD': 'my_secret_password',
'HOST': 'localhost',
'PORT': '5432',
'ATOMIC_REQUESTS': True
},
'readonly': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'myprojectdb',
'USER': 'myprojectreadonly',
'PASSWORD': 'your_eyes_only_secret',
'HOST': 'localhost',
'PORT': '5432',
'ATOMIC_REQUESTS': True
}
}
And now django throws a couple different errors. If I try to do anything with migrations, I get:
django.db.utils.ProgrammingError: permission denied for relation django_migrations
If I try to runserver, I get:
"AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'users.User' that has not been installed
It seems like when I add the second database setting, django is attempting to use that for migrations, running the server, etc, even though it's not 'default'
If I comment out the second entry, everything works great again.
Any recommendations on how to correct this?
Edit: If I change the settings to use the same username and password, everything works great, so it's not just an issue of django being confused on names. IE:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'myprojectdb',
'USER': 'myprojectuser',
'PASSWORD': 'my_secret_password',
'HOST': 'localhost',
'PORT': '5432',
'ATOMIC_REQUESTS': True
},
'readonly': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'myprojectdb',
'USER': 'myprojectuser',
'PASSWORD': 'my_secret_password',
'HOST': 'localhost',
'PORT': '5432',
'ATOMIC_REQUESTS': True
}
}
The two configurations shares the same database names 'NAME': 'myprojectdb'
So when you try to migrates dbname seems to conflicts so the applications is having an indecision on which to use The previous or the later
DATABASE_OPTIONS = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'student',
'USER': 'root',
'PASSWORD': 'pooja',
'HOST': 'localhost',
'PORT': 3306,
'init_command': 'SET storage_engine=INNODB, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED'
},
}
Exception IS:
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
I am using mysql database I am getting above exception in django while migrating model to the database please let me know what is the error what i ma doing wrong here.
thanks you for your reply
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'student',
'USER': 'root',
'PASSWORD': 'pooja',
'HOST': 'localhost',
'PORT': 3306,
'init_command': 'SET storage_engine=INNODB, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED'
},
}