I am trying to install cvat, so I am following the Installation guide
The first step run smoothly, however when I try to create a superuser with the command
docker exec -it cvat_server bash -ic 'python3 ~/manage.py createsuperuser'
After a few minutes, I get the following error:
Traceback (most recent call last):
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/opt/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/opt/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/opt/venv/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection timed out
Is the server running on host "cvat_db" (172.18.0.3) and accepting
TCP/IP connections on port 5432?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/django/manage.py", line 21, in <module>
execute_from_command_line(sys.argv)
File "/opt/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/opt/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/venv/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 79, in execute
return super().execute(*args, **options)
File "/opt/venv/lib/python3.8/site-packages/django/core/management/base.py", line 397, in execute
self.check_migrations()
File "/opt/venv/lib/python3.8/site-packages/django/core/management/base.py", line 486, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/opt/venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/opt/venv/lib/python3.8/site-packages/django/db/migrations/loader.py", line 53, in __init__
self.build_graph()
File "/opt/venv/lib/python3.8/site-packages/django/db/migrations/loader.py", line 220, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/opt/venv/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/opt/venv/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/opt/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/opt/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/opt/venv/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/opt/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/opt/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/opt/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: could not connect to server: Connection timed out
Is the server running on host "cvat_db" (172.18.0.3) and accepting
TCP/IP connections on port 5432?
What should I do to fix this and use CVAT?
My Ubuntu version: Ubuntu 22.04.1 LTS
I thought adding Django's authentication system might solve it so I did pip install django-auth but it changed nothing
I have had the same problem but I found a solution. Some user suggested a problem with docker installation here. My way to solve it is:
Remove docker installation completely. This can help.
Install docker from the atp repository:
sudo apt install containerd
sudo apt install docker.io
Do everything as in the CVAT installation guide, but ignore the part about installing Docker and use the commands above. With this solution some comands indicated in the installation guide will require sudo. In the guide:
Instead of docker compose up -d use sudo docker-compose up -d
Run with sudo docker-compose up
Related
I know it may be a novice problem but I got stuck here for quite some time.
In my azure account I wanted to deploy my django-postgresql project in a subdomain. so I did the following steps,
Created a python webapp with linux resource
Created a postgresql server (single server) with the same resource
Setup CI/CD in Development center
Also set the production.py file in my project and set those variable values in the Configuration of my App service.
I successfully created my database in postgresql using azure CLI (This is the only step I use CLI in this process)
Then I opened my SSH session and activated antenv. After that I ran the python manage.py migrate command and got the following error....
Traceback (most recent call last):
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/opt/python/3.8.6/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.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?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 92, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/migrations/loader.py", line 53, in __init__
self.build_graph()
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/migrations/loader.py", line 216, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/opt/python/3.8.6/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/opt/python/3.8.6/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
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?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
FYI, I am not using docker and azure CLI for creating webapp. I only used azure CLI to create the database.
Can you please help me with this?
Thanks.
As the error message, your app service could not connect to server, here are something you need to check:
Check if you already set all of the required app settings like mine:
Check if you enable the Allow access to Azure Service in Azure Database for PostgreSQL server's Firewall rules:
If you are new to this, you could follow this tutorial first.
It is related to the settings files for multiple deployments. Most probably one of your deployment settings uses local postgresql another one uses azure postgresql. Then because of wrong import or another reason, azure webapp uses host of local deployment (which is localhost if not provided).
EDIT 1
have added _test.py with postgresql database connexion data but failed when I run I run the command py manage.py test cafe.tests.CafeTestCase --settings=core.settings._test
RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against the production database when it's not needed (for example, when running tests). Django was unable to create a connection to the 'postgres' database and will use the first PostgreSQL database instead.
warnings.warn(
Traceback (most recent call last):
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
self.connect()
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\postgresql\base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\psycopg2\__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\core\management\commands\test.py", line 23, in run_from_argv
super().run_from_argv(argv)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\core\management\commands\test.py", line 53, in handle
failures = test_runner.run_tests(test_labels)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\test\runner.py", line 629, in run_tests
old_config = self.setup_databases(aliases=databases)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\test\runner.py", line 552, in setup_databases
return _setup_databases(
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\test\utils.py", line 170, in setup_databases
connection.creation.create_test_db(
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\creation.py", line 58, in create_test_db
self._create_test_db(verbosity, autoclobber, keepdb)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\creation.py", line 168, in _create_test_db
with self._nodb_connection.cursor() as cursor:
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\base.py", line 256, in cursor
return self._cursor()
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\base.py", line 233, in _cursor
self.ensure_connection()
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
self.connect()
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
self.connect()
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\base\base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\django\db\backends\postgresql\base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "D:\Users\jl3\DevSpace\Envs\envIntensecovAPI\lib\site-packages\psycopg2\__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError
I have a Django app set with Docker and different developpement environment: dev, preprod, prod.
I use a postgresql database / pgaadmin 4 in my local Windows environment
I want to write and run tests 'outside' Docker in a VSCode terminal
(because if I use web container to run tests, changes in my tests.py are not updated so I need to down, build and re-run my containers)
so I run the command py manage.py test cafe.tests.CafeTestCase --settings=core.settings.preprod where I speficy the settings to consider
But I got an error sqlite3.OperationalError: no such function: Now because some data migrations use timezone.now() that i not available in sqlite
but I have specify test_database in my settings and given access to user so test should consider postgresql no?
_test.py
DATABASES = {
'default': {
"ENGINE": "django.db.backends.postgresql",
"NAME": "db_preprod",
"USER": "user_preprod",
"PASSWORD": "user_preprod",
"HOST": "localhost",
"PORT": "5433",
'TEST' : {
'NAME': 'test_db_preprod',
}
}
}
so you just have to create the database (or use an existing database) in your _test.py settings
Since SQLite does not provide the now() function, you need to to replace now() by datetime('now')
I've been looking everywhere but cannot seem to find anyone with my same problem. Here's my situation...
Django App: Running on Centos7 Vagrant guest 10.0.0.2 connecting to DB
Postgresql-10 DB: Running on Centos7 Vagrant guest 10.0.0.1 serving the Django app, also has pgAdmin4 running on it
When I bring these vagrant machines up they are able to initially connect. I notice when I leave them idle for periods of time then the Django app cannot connect any longer to the DB. Even weirder, most of the time, but not all the time, I simply needed to restart the postgresql database service and it would be able to connect again. Right now that's not even the case so I can no longer ignore this problem by just restarting the DB service.
Any ideas on what could be going on here? I've tried a couple things but nothing seems to work. My feeling is it's something on the database machine causing issues since like I said usually this just required a simple restart of the DB service to fix.
I'm completely confused by how it just loses connection sometimes randomly.
Below is the error that is printed out when I try to restart the django app and run "python3 manage.py makemigrations"
-----> Making database migrations
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib64/python3.6/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "10.0.0.1" and accepting
TCP/IP connections on port 5432?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 101, in handle
loader.check_consistent_history(connection)
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/loader.py", line 290, in check_consistent_history
applied = recorder.applied_migrations()
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib64/python3.6/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "10.0.0.1" and accepting
TCP/IP connections on port 5432?
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib64/python3.6/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "10.0.0.1" and accepting
TCP/IP connections on port 5432?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 92, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/loader.py", line 53, in __init__
self.build_graph()
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/loader.py", line 216, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib64/python3.6/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "10.0.0.1" and accepting
TCP/IP connections on port 5432?
I tried to deploy my Django project on Heroku but everytime I try 'heroku run python3 manage.py migrate' I get this error:
/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 168, in get_new_connection
connection = Database.connect(**conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.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?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 79, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/loader.py", line 206, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 61, in applied_migrations
if self.has_table():
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 44, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 255, in cursor
return self._cursor()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 232, in _cursor
self.ensure_connection()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 168, in get_new_connection
connection = Database.connect(**conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
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 already researched and tried tons of solutions but nothing works. I changed the localhost to * in postgres.conf file, I changed 127.0.0.1/32 into 0.0.0.0/0 in pg_hba.conf, I restarted Postgres thounsands of times and Im sure its running. I'm using Linux and virtual env. Are there even any options left?
Alright, I got the solution. I need to add this into my settings.py file:
from decouple import config
DATABASES = {
'default': dj_database_url.config(
default=config('DATABASE_URL')
)
}
I deleted my postgresql database from pgAdmin III (right click on databases/mydatabase => delete/drop).
Now I want start anew and make the first migration that should create the database but instead it give an error: database don't exist.
Until now I was using sqlite3 and this procedure worked.
What I should do?
Full traceback:
(myvenv) c:\Python34\Scripts\possedimenti\sitopossedimenti>manage.py migrate
Traceback (most recent call last):
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 199, in ensure_connection
self.connect()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\postgresql\base.py", line 175, in get_new_connection
connection = Database.connect(**conn_params)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\psycopg2\__ini
t__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: FATALE: il database "possedimenti_database" non esis
te
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Python34\Scripts\possedimenti\sitopossedimenti\manage.py", line 10, i
n <module>
execute_from_command_line(sys.argv)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\base.py", line 399, in execute
output = self.handle(*args, **options)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\commands\migrate.py", line 89, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\loader.py", line 49, in __init__
self.build_graph()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\loader.py", line 176, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\recorder.py", line 52, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_name
s(self.connection.cursor()):
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 231, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 204, in _cursor
self.ensure_connection()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 199, in ensure_connection
self.connect()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\util
s.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\utils\s
ix.py", line 685, in reraise
raise value.with_traceback(tb)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 199, in ensure_connection
self.connect()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\postgresql\base.py", line 175, in get_new_connection
connection = Database.connect(**conn_params)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\psycopg2\__ini
t__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: FATALE: il database "possedimenti_database" n
on esiste
First migration doesn't create the database, it needs existing database to create tables in it.
To create postgres database run from your terminal:
createdb -U postgres possedimenti_database
You might have to replace postgres in above command with your database user.
check the details in your settings.py for your DB. Recreate the PostgreSQL database using those exact same details (port number, user, host, password etc). Try this existing solution here link here:
PostgreSQL - create a new DB through pgAdmin UI in order to create the DB via pgAdmin