I have successfully followed the Django 1.4 Tutorial 1-4 (the poll system) and now its running until I deploy it in Apache Webserver 2.2 using Postgres Database. Everytime I access localhost I always have "Internal Server Error" but if I use MySQL as my database everything is ok. What do you think is wrong? Did I miss something to configure in Postgre?
Here is my database connection settings in Mysql(Working) and in Postgre(Not Working), both using Apache2.2 + mod_wsgi.so
//Postgre
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_demo1',
'USER': 'postgres',
'PASSWORD': 'mypassword',
'HOST': 'localhost',
'PORT': '',
}
}
//MySQL
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_demo1',
'USER': 'root',
'PASSWORD': 'mypassword',
'HOST': 'localhost',
'PORT': '',
}
}
Other INFO:
OS: windows 7, Python: 2.7, Django: 1.4, Postgre 9.1
If you are able to access MySQL but not Postgres, I guess psycopg2 which is the Postgres adapter for python is not installed. Install psycopg2 using pip.
pip install psycopg2
Here is the pypi.
Related
I can import migrations with Sqlite3 in my Django project, but when I try to import it with postgreql, I get an error like this. How can I fix this?
I installed before
pip install psycopg2
pip install django psycopg2
Error
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError
DB Settings Django
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'lordplusdb',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
Try to use the following value for the engine:
'ENGINE': 'django.db.backends.postgresql'
The added _psycopg2 is for older versions of Django.
https://docs.djangoproject.com/en/3.0/internals/deprecation/#deprecation-removed-in-3-0
This message showed after I executed runserver command:
System check identified no issues (0 silenced)
I have referenced this solution, but it didn't work for me(I start my mysql server by the command
"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld"
).
Here is the background information(the "pip list" command):
(DjangoEnv) D:\pythonproject\DjangoEnv\loginoutonly>pip list
Package Version
Django 2.1.5
mysqlclient 1.3.13
pip 18.1
PyMySQL 0.9.3
pytz 2018.9
setuptools 40.6.3
wheel 0.32.3
Here is the db information in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'loginoutonly',
'USER': 'root',
'PASSWORD': 'pwd',
'HOST': 'localhost',
'PORT': '3306'
}
}
XAMPP helped me.
XAMPP says that
Port 3306 in use by "Unable to open process"!
I change my MySQL port to 3307 using XAMPP [Config] button.
Then, I change my settings.py code to
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'loginoutonly',
'USER': 'root',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '3307'
}
}
I also need to test the MySQL WorkBench connection of this newly connected port "3307".
I'm trying to make the migrations between my database (MySQL) and Django. I used the same parameters in Linux and didn't have any problems. Now I'm using the command :
python manage.py migrate
and I get nothing at all on the terminal. However, the command works if I let the default parameters ( for a sqlite database ). Also, I've noticed that it actually reads the 'settings.py' file because it returns an error if I write something that doesn't make any sense. Here are my parameters, I know for sure that they are correct ( I checked with the MySQL commands ).
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_db',
'USER': 'root',
'PASSWORD': '123456789_dont_judge_me',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
Error message
I'm using Windows 10, Python 3.5 and Django 2.0.
Do you have any idea where the problem could come from ?
Thank you for your responses kind people !
You can try this.
Note: I am not claiming it is best solution, but it is working for me
in case of Window10.
Step1 : Install pymysql
pip install pymysql
Step2: Edit settings.py
settings.py
---------------
import os
import pymysql
pymysql.install_as_MySQLdb()
import MySQLdb
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_test',
'USER': 'root',
'PASSWORD': '123456',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
Step3: migrate it
python manage.py migrate
you can follow this link
I am trying to connect to oracle 10g XE database from windows but getting following error
Here is my settings for database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'xe',
'USER': 'xxx',
'PASSWORD': 'xxx',
'HOST': '127.0.0.1',
'PORT': '1527',
}
}
installed libraries
cx-Oracle==6.1
Django==1.11.10
pytz==2018.3
Tried to identify solutions but found nothing related
the problem was cx-Oracle version. unfortunately cx-Oracle 6.1 does not support oracle 10g so downgraded to cx-Oracle 5.3 and connection was established successfully
cx-Oracle==5.3
I have made a virtual environment and installed following:
sudo apt-get install libmysqlclient-dev
sudo pip install MySQL-python
and my setting is :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB_NAME',
'USER': 'DB_USER',
'PASSWORD': 'DB_PASSWORD',
'HOST': 'localhost',
'PORT': '3306',
}
}
and when I do manage.py syncdb it gives the error saying 2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
I dont know whats wrong in here...
I searched for it... Mostly I found if I use virtualenvironment then the above setting is enough... Whats wrong in here ???
Install mysql server
sudo apt-get install mysql-server
then create a database for your purposes:
mysql -u root -p --execute "create database DB_NAME; grant all on DB_NAME.* to DB_USER#localhost identified by 'DB_PASSWORD';"
then you should be fine.
I should point out that the confusion of mysql searching for a socket, even if specifying a port, is because mysql defaults to a socket when specifying localhost as an address, if you want to use tcp/ip then you should put an address like 127.0.0.1 there.
Your HOST should change to '127.0.0.1', you must start service, especially if you are using xamp or lamp.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB_NAME',
'USER': 'DB_USER',
'PASSWORD': 'DB_PASSWORD',
'HOST': '127.0.0.1',
'PORT': '3306',
} #Your HOST should change to '127.0.0.1', you must start service, especially if you are using xamp or lamp