I'm running Django 1.6 with MySQL on pythonanywhere.com. In the bash command line:
mysqldb has been pip installed
i can access mysql database from the command line with $ mysql -h $your_IP =P 3306 -u username -p
However, when I try and run python manage.py syncdb I get an error that ends with this:
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'mysql.server' (111)")
In my django settings I have
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydatabasename',
'USER': 'myusername',
'PASSWORD': 'mypassword',
'HOST': 'mysql.server',
'PORT': '3360',
}
}
I tried running python manage.py test and python manage.py testserver and got the exact same error. I tried python -v manage.py etc to get the verbose spit out and it seems a lot of other stuff is failing to import? Could it be that the settings.py isnt being found? The whole set up worked perfectly fine local, and all I've done is push it to the server and changed the database settings.
Any idea???
Your settings read port as 'PORT': '3360', change that to 3306. Also, make sure mysql.server is a valid server host. Or it could just be localhost
Related
I am trying to run a Django application on AWS Ec2 instance. I've chosen Ubuntu as my platform. After cloning the git repository, and creating a virtual environment, I have installed all apps in my requirements.txt. When I try to the following lines of code python3 manage.py migrate ; python3 manage.py check ; python3 manage.py runserver the following error is coming up.
django.db.utils.OperationalError: connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "columbus_db" connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "columbus_db"
My settings.py file looks like this
DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Database Engine of PostgreSQL Database
'NAME': 'columbus_db', # Database Name
'USER': 'columbus_db', # Database has a Root User
'PASSWORD': 'columbus', # Database Connection Password
'HOST': "localhost", # IP Address for Localhost
}
What can I change in settings.py or Ec2 Instance settings to start the application and see it at Ec2 IP address?
You are missing a running database, the app code except it to be PostgreSQL, you have multiple choices:
Install and run a local PostgreSQL instance directly in your EC2
Use Amazon's managed database RDS
Use Sqlite which is simple to setup and doesn't require more configuration, but your app might required specific PostgreSQL features
I installed postgresql 14 on my windows 11. Set it up to run on port 5432 (the default one).
Completed the installation but when I try to run python3 manage.py makemigrations it throws an error saying:
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
I checked in services and postgresql is running.
I ran the \conninfo command and here are the results of that command:
Here is what my pgAdmin looks like
I'm running the script using venv. Here is the settings.py page script
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'bidgala',
'USER': 'postgres',
'PASSWORD': 'Abhi1331',
'HOST': '127.0.0.1'
}
}
I looked for many solutions like restarting the service and such but didn't workout for me.
I could really use some help here!!.
Hello I'm currently trying to implement Buddy with my little StartUp that is using DJANGO REST FRAMEWORK as a base. I found a very good example on the site. Unfortunately in the exmaple the used a MySql DB and I'm using Postgre as DB. My settings.py is:
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'DBname',
'USER': 'DBuser',
'PASSWORD': 'DBpassword',
'HOST': '',
'PORT': '5432',
}
}
}
My Buddy execute look somethig like this:
pip install -r requirements.txt
cd Project
python manage.py test
I also created postgre service in Buddy
like version: latest, Hostname: postgres, Port:5432, Login:DBuser, Password:DBpassword, Name of a database to be created on container startup: DBname
When I run the build Test of my project an error message apears like this:
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Action failed: see logs above for details
I really don't now how to fix this, it appears that Buddy creates the database correctly but for some reason django does not reconise that it exists.
Pd: The proyect works fine on my laptop and my friends. I'ts only when I tried to run it on buddy where it gives me problems
Forgive me as I this is my first django project using postgresql (version 11.8). For now I just want to connect to a test database which I have set up locally using pgadmin4. When I create the database I am not given the option to add a password, but when I run python manage.py migrate it is insisting on a password. When I then set the password to "password" on pgadmin, django won't accept it. It's probably something really obvious as I am quite new to Django, but I have tried searching and not found the answer to my problem. In settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'test1',
'USER': 'postgres',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
Last line of the error when I run python manage.py migrate:
django.db.utils.OperationalError: fe_sendauth: no password supplied
Any help much appreciated. Craig
When you installed PgAdmin4 it asked you to create a password. This is for the superuser postgres, which is what you are trying to connect as. Use psql to connect to the database using the above settings and supply the password and see if it works.
I resolved it by removing the Postgresql 11 server and reinstalling it.
I'm using docker as MySQL server, in docker I use:
docker run --name what -e MYSQL_ROOT_PASSWORD=abc123 -e MYSQL_DATABASE=mami -p 3306:3306 -d mysql
After that I tested it in MySQL workbench.
It works fine with 192.168.99.100:3306 and root/abc123
but when I try to connect it via django:
import pymysql
pymysql.install_as_MySQLdb()
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mami',
'USER': 'root',
'PASSWORD': 'abc123',
'HOST': '192.168.99.100',
'PORT': '3306',
}
}
It gives me django.db.utils.OperationalError: (1045, "Access denied for user 'root'#'192.168.99.1' (using password: NO)") when I run application or just doing python manage.py migrate
I'm Using Windows and Python 3.6, what am I doing wrong?
Thanks in advance for any help!