Django Oracle connection as SYS should be as SYSDBA or SYSOPER - python

I'm trying to use Oracle Database for Django. Oracle DB is active and I can connect with SQLDeveloper. But cannot connect from Django to Oracle DB.
I got this error:
django.db.utils.DatabaseError: ORA-28009: connection as SYS should be as SYSDBA or SYSOPER
I use Conntection Type = Basic, Role = SYSDBA in SQLDeveloper. Where to give this parameters in Django?
My Current setting.py parameters:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'payman',
'USER': 'sys',
'PASSWORD': 'ssys',
'HOST': '172.55.79.9',
'PORT': '1521',
}
}

You need to provide this in the 'OPTIONS' to cx_oracle. I set the following while using the full DSN mode:
'OPTIONS': {
'purity': cx_Oracle.ATTR_PURITY_SELF,
'mode': cx_Oracle.SYSDBA
},

Related

Can I access other MySQL database in Python Django without having access to its models?

I have this connection to MySQL Workbench database. The thing is, the database and tables isn't made by my Django project so I don't have any access to its class models. Is there any way I can add, update or delete in the database tables?
tables: TestTable1, TestTable2, TestTable3
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test',
'USER': 'root',
'PASSWORD': '1234',
'PORT': 3306,
'HOST': '127.0.0.1',
'OPTIONS': {
'charset': 'utf8mb4',
'use_unicode': True, },
}
}
You can use custom sql directly. Have a look at:
https://docs.djangoproject.com/en/3.2/topics/db/sql/#executing-custom-sql-directly

Django fails to connect to remote MongoDB server using djongo

I try to connect to use a MongoDB database for the Django project.
So I follow a tutorial for changing the DATABASE from settings.py
# Original
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'testDB',
}
Changed to
# From tutorials
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'testDB',
'USERNAME': 'username',
'PASSWORD': 'password',
'HOST': 'myhostname.example',
'PORT': '27017',
}
}
Trying to run
python manage.py makemigrations
python manage.py migrate
All works, but no data in my database
Apparently django went for the localhost:27017 host and created a database there.
Uninstalling MongoDB, just caused makemigrations to fail
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [WinError 10061] No connection could be made because the target machine actively refused it
I found a solution.
https://stackoverflow.com/a/60244703/7637454
To fulfill the answer here this is how you're supposed to configure it now.
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'yourmongodb',
'CLIENT': {
'host': 'some-host.or.ip',
'port': 27017,
'username': 'youruser',
'password': 'yourdbpass',
'authSource': 'yourcollection', # usually admin
}
},
}
The answer provided, does not work for me, instead I adopted following approach.
So, behind the scene, the Djongo uses PyMongo and PyMongo's default configuration are:
class MongoClient(common.BaseObject):
HOST = "localhost" # here HOST has the hardcoded value
PORT = 27017
which are in the following file:
venv/lib/python3.6/site-packages/pymongo/mongo_client.py
replace the harcoded value of HOST to something like
HOST = 'mongodb+srv://<username>:<password>#cluster-name/<dbname>?retryWrites=true&w=majority'
Additionally, we can set the environment variable if we want
HOST = os.getenv('MONGO_DB_URL')

Django not finding database despite it existing

I'm trying to change the default database used in Django to MySQL, I've adjusted my settings.py file like so:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'clients',
'HOST': 'localhost',
'PORT': '3307',
'USER': 'root',
'PASSWORD': '*****',
}
}
I'm still getting the django.db.utils.OperationalError: (1049, "Unknown database 'clients'"). When I try to connect to the 'mysql' database that comes default with MySQL I have no issue. I get this error when I try to use manage.py makemigrations,migrations or runserver. I have MySQL-Python installed and everything. Proof that my clients database exists:

django.db.utils.OperationalError: (1046, 'No database selected')

Getting a strange error. I created a database in MySQL, set the database to use it. Using the right settings in my Django settings.py. But still there's an error that no database has been selected.
First I tried:
python manage.py syncdb
Got this traceback:
django.db.utils.OperationalError: (1046, 'No database selected')
settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_db',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
}
}
What have I missed?
Check to make sure your database my_db exists in your MySQL instance. Log into MySQL and run;
show databases;
make sure my_db exists. If it does not, run
create database my_db;
GRANT access privileges to the user mentioned in the file
GRANT ALL PRIVILEGES ON database_name.* TO 'username'#'localhost';
You need not grant all privileges. modify accordingly.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_db',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
}
}
Here name means database
Just delete database my_db and create again
Step 1:- Use drop database databaseName
Step 2:- Create Database databaseName
Then use the migrate command
It will definitely work

1049, "Unknown database 'database' " django mysql can't connect

Exception Type: OperationalError at /
Exception Value: (1049, "Unknown database 'database'")
At the moment i tried this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'database', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': '****', # Not used with sqlite3.
'HOST': '/var/lib/mysql/database/', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '80', # Set to empty string for default. Not used with sqlite3.
}
}
If i don't specify a host i get this error:
OperationalError at /
(2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/database' (13)")
Can it be something with permissions?
thanks in advance :)
First, create the database on mysql.
Second, edit your default conection like this.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'MY_DATABASE_NAME',
'USER': 'root',
'PASSWORD': 'MY_PASSWORD',
}
}
finally run your syncdb.
./manage.py syncdb
PORT is not the web server port, but the database port, which is 3306 for MySQL, and HOST is the database sever's IP or name. You probably want 127.0.0.1.
You should create the database beforehand with create database mydatabase charset utf8; from the mysql prompt.
Login to mysql on Terminal and create a DB
mysql -u root -p
CREATE DATABASE dbname;
USE dbname;
Then on setting.py file
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname',
'USER': 'root', #Mysql username
'PASSWORD': 'password', #mysql password
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
I dont think you can create a database by the name database. So please check the following first...
1) Have installed mysql-server and created the database with proper grant all permissions? If you have done so then check next steps
2)I dont know about Amazon, but this error was common in older versions of Linux distros from Redhat and Fedora. An option is to do this
by setting the SELINUX line in /etc/sysconfig/selinux to Disabled:
SELINUX=Disabled

Categories