我的django项目早先使用过sqlite,但现在我们已将其更改为使用Postgresql。以下是新设置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'vader',
'USER': 'root',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '5432',
}
}
我创建了一个db vader和root用户作为其所有者。现在,当我尝试使用以下命令应用迁移时:
python manage.py migrate
我收到以下错误:
(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
这是说没有提供密码,但我不知道在哪里传递密码。我有什么想法可以解决这个问题吗?
答案 0 :(得分:1)
您需要将数据库用户密码添加到settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'vader',
'USER': 'root',
# Add password here
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '5432',
}
}
答案 1 :(得分:1)
您需要像这样删除PASSWORD
,HOST
和PORT
:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'vader',
'USER': 'root'
}
}
然后再次进行迁移。