django.db.utils.OperationalError:严重:用户“无业游民”的密码身份验证失败

时间:2020-04-08 17:44:31

标签: python django python-2.7 vagrant

我带端口和所有物品的无用物品盒存在问题,所以我做过一些我怀疑自己无法运行./manage.py migrate的能力。这是我运行vagrant ssh-config

时的样子
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/brock1hj/projects/sodium/to-vagrant/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL

这是完整的错误:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 93, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/migrations/executor.py", line 19, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/migrations/loader.py", line 47, in __init__
    self.build_graph()
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/migrations/loader.py", line 180, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
    self.ensure_schema()
  File "/Users/brock1hj/envs/sodium/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.table_names(self.connection.cursor()):
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/backends/base/base.py", line 162, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/backends/base/base.py", line 135, in _cursor
    self.ensure_connection()
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/backends/base/base.py", line 119, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/Users/brock1hj/envs/sodium/lib/python2.7/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL:  password authentication failed for user "vagrant"

我真的不确定发生了什么,我认为用户“ vagrant”的密码以某种方式从默认的“ vagrant”更改了。

我正在使用Django 1.8.2

这是我的数据库settings.py文件:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'vagrant',
        'USER': 'vagrant',
        'PASSWORD': 'vagrant',
        'HOST': '127.0.0.1',
        'PORT': '',
    }
}

我觉得它将尝试尝试将“无用”作为密码,但是情况不再如此。

尝试输入dbshel​​l时,系统提示您输入密码,以确保“ vagrant”不起作用并得到:

Password for user vagrant:
psql: error: could not connect to server: could not initiate GSSAPI security context: Unspecified GSS failure.  
Minor code may provide more information could not initiate GSSAPI security context: Configuration file does 
not specify default realm
FATAL:  password authentication failed for user "vagrant"

1 个答案:

答案 0 :(得分:0)

尝试:

  1. vagrant ssh
  2. psql
  3. 然后按照https://www.postgresql.org/docs/9.6/sql-alterrole.html上的说明进行操作,看起来像您想要的ALTER ROLE vagrant PASSWORD 'vagrant';