My django project earlier used sqlite, but now we have changed it to use Postgresql. Here are the new settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'vader',
'USER': 'root',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '5432',
}
}
I have created a db vader and user root as its owner. Now, when I try to apply migrations with:
python manage.py migrate
I get the following error:
(env1)sushil#Linux-Machine:~/Adomattic/Vader$ python manage.py migrate
[profile] heap size is 22.5 MB
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 63, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 17, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 184, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.get_table_list(self.connection.cursor()):
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 165, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 138, in _cursor
self.ensure_connection()
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
self.connect()
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
self.connect()
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 122, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 134, in get_new_connection
return Database.connect(**conn_params)
File "/home/sushil/Adomattic/env1/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: fe_sendauth: no password supplied
It is saying no password supplied, but I am not sure where to pass the password. Any ideas what I can do to fix this?
You need to add your database user password to your settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'vader',
'USER': 'root',
# Add password here
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '5432',
}
}
You need to remove PASSWORD, HOST and PORT like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'vader',
'USER': 'root'
}
}
Then do the migrate again.
Related
i change my database django default to postgresql and when i try to migrating ...
django.db.utils.OperationalError: FATAL: password authentication failed for user "hamid"
my settings is
install psycop2 but i dont understad my mistake becuse i can enter to shell database by this password but when i migrating i have error
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USRE': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'localhost',
'PORT': '5432',
}
}
and my docker-compose.yml
version: '3'
services:
blogpy_postgresql:
image: postgres:12
container_name: blogpy_postgresql
volumes:
- blogpy_postgresql:/var/lib/postgresql/data
restart: always
env_file:.env
ports:
- "5432:5432"
networks:
- blogpy_network
volumes:
blogpy_postgresql:
external: true
networks:
blogpy_network:
external: true
and my .env
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=postgres
and my traceback
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL: password authentication failed for user "hamid"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "./manage.py", line 21, in <module>
main()
File "./manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 87, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/migrations/loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
if self.has_table():
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 256, in cursor
return self._cursor()
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 233, in _cursor
self.ensure_connection()
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/hamid/Documents/django/venv/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL: password authentication failed for user "hamid"
i use python3
and django 2.2
You have a typo in your databases settings.
'USRE': 'postgres',
should be
'USER': 'postgres',
I'm trying to deploy django on to AWS EB. I have a RDS linked to the instance and database is migrated without any problem.
When I log onto the server using ssh and try to create a superuser, I run into following errors:
django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (111)")
I used the same setup for several other django site, didn't have the same problem.
The only difference this time is in the view I'm using native sql, I wonder if the connection.cursor() is causing this problem.
In settings I have:
if 'RDS_HOSTNAME' in os.environ:
print "live site server connection: ", os.environ['RDS_HOSTNAME']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ['RDS_DB_NAME'],
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
},
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'new_dash',
'USER': 'root',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
/opt/python/run/venv/bin/python manage.py createsuperuser
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 63, in execute
return super(Command, self).execute(*args, **options)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 342, in execute
self.check()
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 361, in _run_checks
return checks.run_checks(**kwargs)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/checks/model_checks.py", line 30, in check_all_models
errors.extend(model.check(**kwargs))
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 1266, in check
errors.extend(cls._check_fields(**kwargs))
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 1337, in _check_fields
errors.extend(field.check(**kwargs))
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 893, in check
errors = super(AutoField, self).check(**kwargs)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 208, in check
errors.extend(self._check_backend_specific_checks(**kwargs))
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 311, in _check_backend_specific_checks
return connections[db].validation.check_field(self, **kwargs)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/mysql/validation.py", line 41, in check_field
field_type = field.db_type(connection)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 629, in db_type
return connection.data_types[self.get_internal_type()] % data
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 183, in data_types
if self.features.supports_microsecond_precision:
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/mysql/features.py", line 54, in supports_microsecond_precision
return self.connection.mysql_version >= (5, 6, 4) and Database.version_info >= (1, 2, 5)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 367, in mysql_version
with self.temporary_connection() as cursor:
File "/usr/lib64/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 564, in temporary_connection
cursor = self.cursor()
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 231, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 204, in _cursor
self.ensure_connection()
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 263, in get_new_connection
conn = Database.connect(**conn_params)
File "/opt/python/run/venv/local/lib64/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/opt/python/run/venv/local/lib64/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (111)")
I am unable to migrate my code. I created a database and a table in MySql but I had to uninstall MySql for some reason and when I installed it again, I changed the user name to root. Now it keeps saying
(1045, "Access denied for user 'djanu'#'localhost' (using password: NO)")
when I try to migrate. I named my user as djanu when I first installed it and I tried granting privileges to user root but the same message keeps popping up.
this is my code in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'applics',
'USER': 'root',
'Password': '531010',
'HOST': '',
'PORT': '',
}
}
and my code when I use python manage.py migrate or even runserver
(myproject) C:\Users\home\myproject\collapp>python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\home\myproject\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Users\home\myproject\lib\site-packages\django\core\management\__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\home\myproject\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\home\myproject\lib\site-packages\django\core\management\base.py", line 342, in execute
self.check()
File "C:\Users\home\myproject\lib\site-packages\django\core\management\base.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\home\myproject\lib\site-packages\django\core\management\commands\migrate.py", line 61, in _run_checks
issues = run_checks(tags=[Tags.database])
File "C:\Users\home\myproject\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\home\myproject\lib\site-packages\django\core\checks\database.py", line 10, in check_database_backends
issues.extend(conn.validation.check(**kwargs))
File "C:\Users\home\myproject\lib\site-packages\django\db\backends\mysql\validation.py", line 9, in check
issues.extend(self._check_sql_mode(**kwargs))
File "C:\Users\home\myproject\lib\site-packages\django\db\backends\mysql\validation.py", line 13, in _check_sql_mode
with self.connection.cursor() as cursor:
File "C:\Users\home\myproject\lib\site-packages\django\db\backends\base\base.py", line 231, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "C:\Users\home\myproject\lib\site-packages\django\db\backends\base\base.py", line 204, in _cursor
self.ensure_connection()
File "C:\Users\home\myproject\lib\site-packages\django\db\backends\base\base.py", line 199, in ensure_connection
self.connect()
File "C:\Users\home\myproject\lib\site-packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\home\myproject\lib\site-packages\django\db\backends\base\base.py", line 199, in ensure_connection
self.connect()
File "C:\Users\home\myproject\lib\site-packages\django\db\backends\base\base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\home\myproject\lib\site-packages\django\db\backends\mysql\base.py", line 263, in get_new_connection
conn = Database.connect(**conn_params)
File "C:\Users\home\myproject\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Users\home\myproject\lib\site-packages\MySQLdb\connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1045, "Access denied for user 'djanu'#'localhost' (using password: NO)")
This has happened many times with me. Possible solution will be to delete all your migrations from migration folder and then running manage.py migrate.
I am new to programming and learning the web development. I have installed:
-Django 1.9
-postgresql 9.5
-psycopg2(using whl file) db api for the postgresql on Windows 7 os.
not a virtual environment.
I have set up the database connection in my settings.py file for my project as following.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'Test',
'User': 'postgres',
'PASSWORD': 'admin',
'HOST': 'localhost',
'PORT': '5432',
}
}
but when I am running migrate I am running in to following problem. I want to connect the postgres to my django
See the error below:
Traceback (most recent call last):
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\db\backends\base\base.py", line 199, in ensure_connection
self.connect()
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\db\backends\base\base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\db\backends\postgresql\base.py", line 175, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\psycopg2\__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)psycopg2.OperationalError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\core\management\__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\core\management\base.py", line 399, in execute
output = self.handle(*args, **options)
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\core\management\commands\migrate.py", line 89, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\db\migrations\executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\db\migrations\loader.py", line 49, in __init__
self.build_graph()
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\db\migrations\loader.py", line 176, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\db\migrations\recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\db\migrations\recorder.py", line 52, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\db\backends\base\base.py", line 231, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\db\backends\base\base.py", line 204, in _cursor
self.ensure_connection()
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\db\backends\base\base.py", line 199, in ensure_connection
self.connect()
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\db\utils.py", line 95, in __exit__six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\db\backends\base\base.py", line 199, in ensure_connection
self.connect()
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\django\db\backends\base\base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\postgresql\base.py", line 175, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\agarwal.s.13\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\psycopg2\__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError
I have checked with python script the psycopg2 is able to connect the database in postgresql but when I am running migrate from django project, its not working and getting above error.
Your database config:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'Test',
'User': 'postgres',
'PASSWORD': 'admin',
'HOST': 'localhost',
'PORT': '5432',
}
}
Should be:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'Test',
'USER': 'postgres',
'PASSWORD': 'admin',
'HOST': 'localhost',
'PORT': '5432',
}
}
Notice that User should be USER
hi im working on a django project with virtualenv that is using the following
Django==1.7.6
argparse==1.2.1
psycopg2==2.6
wsgiref==0.1.2
but when i try python manage.py runserver it gives me this error
Performing system checks...
System check identified no issues (0 silenced).
Unhandled exception in thread started by <function wrapper at 0x7f0574e8c0c8>
Traceback (most recent call last):
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 222, in wrapper
fn(*args, **kwargs)
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 107, in inner_run
self.check_migrations()
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 159, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 17, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 48, in __init__
self.build_graph()
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 183, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.get_table_list(self.connection.cursor()):
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 165, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 138, in _cursor
self.ensure_connection()
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
self.connect()
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
self.connect()
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 122, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 130, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
my settings.py is
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'elfmsdb',
'USER': 'postgres',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
i also checked the postgresql.conf and it is using 5432 as port.
another odd thing is that i accidentally runserver outside my virtualenv and it worked but the django version is 1.6.
please help me, thanks a lot!
I dont know what the problem is but i tried
$sudo service postgresql restart
and runserver worked after that.
may be you can try with this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'elfmsdb',
'USER': 'postgres',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}