简体   繁体   English

无法弄清楚成功运行我的 Django 项目缺少什么

[英]Unable to figure out what's missing to run my Django Project successfully

Last year, I created a Django project on real estate business.去年,我创建了一个关于房地产业务的 Django 项目。 Few days back, I cleaned up my PC & I believe I removed something useful because of which I'm unable to run it on my localhost now.几天前,我清理了我的电脑,我相信我删除了一些有用的东西,因为我现在无法在我的本地主机上运行它。 It was working fine before.它之前工作正常。

The major tools that I used in the project include Django, PostgreSql, pgAdmin4, Bulma.我在项目中使用的主要工具包括 Django、PostgreSql、pgAdmin4、Bulma。 As I'm trying to run it via VSCode, it's showing the following traceback.当我尝试通过 VSCode 运行它时,它显示了以下回溯。 Please help me find out what's exactly missing and how can I get back the proper working flow.请帮助我找出究竟缺少什么以及如何恢复正确的工作流程。

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection       
    self.connect()
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 195, in connect
    self.connection = self.get_new_connection(conn_params)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\postgresql\base.py", line 178, in get_new_connection
    connection = Database.connect(**conn_params)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\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 (0x0000274D/10061)
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
        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 "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 120, in inner_run
    self.check_migrations()
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 453, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
    self.build_graph()
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\loader.py", line 212, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\recorder.py", line 73, in applied_migrations
    if self.has_table():
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\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 "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 256, in cursor
    return self._cursor()
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 233, in _cursor
    self.ensure_connection()
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
    self.connect()
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
    self.connect()
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 195, in connect
    self.connection = self.get_new_connection(conn_params)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\postgresql\base.py", line 178, in get_new_connection
    connection = Database.connect(**conn_params)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python37-32\lib\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 (0x0000274D/10061)
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?

Here's the GitHub link to the source code of my entire project.是我整个项目源代码的 GitHub 链接。

Kalpana Upadhyay卡尔帕纳乌帕迪亚

It is the issue with PostgreSQL .这是PostgreSQL的问题。 There are a lot of possibility for this issue这个问题的可能性很大

From Ricardo Burillo suggestion来自Ricardo Burillo建议

  1. cmd : sudo service postgresql status if PostgreSQL is not running. cmd : sudo service postgresql status如果 PostgreSQL 没有运行。

  2. cmd : sudo netstat -nl | grep postgres cmd : sudo netstat -nl | grep postgres sudo netstat -nl | grep postgres Your PostgresSQl is not running on port 5432. You can check it by execute this cmd . sudo netstat -nl | grep postgres您的 PostgresSQl 未在端口 5432 上运行。您可以通过执行此cmd来检查它。

  3. Problems with postmaster.pid in Postgres. Postgres 中 postmaster.pid 的问题。 It can happen because of a shutdown unproperly done.它可能是由于关闭不当而发生的。 It makes to remind a PID alive that doesn't allow your server to start.它会提醒一个不允许您的服务器启动的 PID 活动。 To fix it you have to要修复它,你必须

    • rm /usr/local/var/postgres/postmaster.pid
    • pg_resetxlog -f /usr/local/var/postgres

For more suggestion, you could check this suggestion if may work for you.如需更多建议,您可以查看此建议是否适合您。

I reinstalled the latest version of PostgreSql & pgAdmin which somehow worked.我重新安装了以某种方式工作的最新版本的 PostgreSql & pgAdmin。 Although I had to set up the entire database thing once again as follows -:虽然我不得不再次设置整个数据库的事情如下 -: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM