运行pgadmin抛出意外错误

时间:2020-07-19 09:42:48

标签: python postgresql ubuntu pgadmin-4

我已经在ubuntu 20.04机器上安装了postgresql和pgadmin。

但是当我在终端上运行以下命令时,我会遇到此错误:python pgAdmin4.py

Traceback (most recent call last):
File "pgAdmin4.py", line 92, in <module>
app = create_app()
File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/pgadmin4/pgadmin/__init__.py", line 350, in create_app
db_upgrade(app)
File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/pgadmin4/pgadmin/setup/db_upgrade.py", line 25, in db_upgrade
flask_migrate.upgrade(migration_folder)
File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/flask_migrate/__init__.py", line 95, in wrapped
f(*args, **kwargs)
File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/flask_migrate/__init__.py", line 280, in upgrade
command.upgrade(config, revision, sql=sql, tag=tag)
File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/alembic/command.py", 
line 298, in upgrade
script.run_env()
 File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/alembic/script/base.py", 
line 489, in run_env
util.load_python_file(self.dir, "env.py")
File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/alembic/util/pyfiles.py", line 98, in load_python_file
module = load_module_py(module_id, path)
   File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/alembic/util/compat.py", line 184, in load_module_py
spec.loader.exec_module(module)
   File "<frozen importlib._bootstrap_external>", line 783, in exec_module
   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
   File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/pgadmin4/pgadmin/setup/../../migrations/env.py", line 94, in <module>
      run_migrations_online()
   File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/pgadmin4/pgadmin/setup/../../migrations/env.py", line 87, in run_migrations_online
     context.run_migrations()
    File "<string>", line 8, in run_migrations
   File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/alembic/runtime/environment.py", line 846, in run_migrations
self.get_context().run_migrations(**kw)
   File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/alembic/runtime/migration.py", line 520, in run_migrations
     step.migration_fn(**kw)
    File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/pgadmin4/migrations/versions/3c1e4b6eda55_.py", line 20, in upgrade
     db.engine.execute(
    File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2238, in execute
      return connection.execute(statement, *multiparams, **params)
    File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1006, in execute
     return self._execute_text(object_, multiparams, params)
    File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1175, in _execute_text
    ret = self._execute_context(
    File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1317, in _execute_context
     self._handle_dbapi_exception(
     File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1511, in _handle_dbapi_exception
      util.raise_(
      File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
      raise exception
      File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1277, in _execute_context
      self.dialect.do_execute(
     File "/home/farhad/Public/pgadmin/pgadmin/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
     cursor.execute(statement, parameters)
  sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) duplicate column name: hostaddr
   [SQL: ALTER TABLE server ADD COLUMN hostaddr TEXT(1024)]
   (Background on this error at: http://sqlalche.me/e/13/e3q8)

在我经常安装它之前,没有任何问题。

我已经使用以下命令安装了postgresql:

sudo apt install postgresql postgresql-contrib

然后我根据以下步骤安装了pgadmin:

  1. 运行命令sudo apt install build-essential libssl-dev libffi-dev libgmp3-dev virtualenv python3-pip libpq-dev python-dev

  2. 在我系统的某个位置创建一个名为pgadmin的目录。

  3. 使用virtualenv创建隔离的环境并运行命令virtualenv pgadmin

  4. cd pgadmin

  5. source bin/activate

  6. 运行命令wget https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v4.23/pip/pgadmin4-4.23-py3-none-any.whl

  7. 使用python pip安装它:pip install pgadmin4-4.23-py3-none-any.whl

  8. 在此路径中创建名为config_local.py的文件:

/pgadmin/pgadmin/lib/python3.8/site-packages/pgadmin4

并将此内容放进去:

import os
DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgAdmin/'))
LOG_FILE = os.path.join(DATA_DIR, 'pgAdmin4.log')
SQLITE_PATH = os.path.join(DATA_DIR, 'pgAdmin4.db')
SESSION_DB_PATH = os.path.join(DATA_DIR, 'sessions')
STORAGE_DIR = os.path.join(DATA_DIR, 'storage')
SERVER_MODE = False
  1. 最后,当我通过命令python /pgadmin/pgadmin/lib/python3.8/site-packages/pgadmin4/pgadmin4.py运行pgadmin时,遇到了该错误。

1 个答案:

答案 0 :(得分:0)

问题与pgadmin的sqlite数据库有关。

sqlite数据库位于~/.pgAdmin/pgAdmin4.db中。我删除了~/.pgAdmin目录,然后重新安装pgadmin。已纠正。