gpt4 book ai didi

django - 在 Windows 中为 django 安装 postgresql

转载 作者:太空宇宙 更新时间:2023-11-03 12:06:54 25 4
gpt4 key购买 nike

我正在学习 django,在这里我试图将数据库从默认的 sqlite3 更改为 postgresql。我在整个互联网上进行了搜索(google、bing、duckduckgo 等),但没有任何结果。

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'websitedb',
'USER': 'postgres',
'PASSWORD': 'teamarrow',
'HOST': 'localhost',
'PORT': '5432',
}
}`

更改了settings.py中的数据库,从 here 安装了 postgresql,为 Windows 安装了 psycopg2 ,在 pgADMINIII 中创建了一个新数据库。

在命令提示符 python manage.py runserver 中。这是错误:

 ` Traceback (most recent call last): 
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\core\management\__ini
t__.py", line 385, in execute_from_command_line
utility.execute()
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\core\management\__ini
t__.py", line 354, in execute
django.setup()
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\__init__.py", line 21
, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\apps\registry.py", li
ne 108, in populate
app_config.import_models(all_models)
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\apps\config.py", line
202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\contrib\auth\models.p
y", line 40, in <module>
class Permission(models.Model):
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\db\models\base.py", l
ine 122, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\db\models\base.py", l
ine 297, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\db\models\options.py"
, line 166, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\db\__init__.py", line
40, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\db\utils.py", line 24
2, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\db\utils.py", line 10
8, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\db\backends\postgresq
l_psycopg2\base.py", line 27, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module n
amed psycopg2

请调试错误所在。

最佳答案

您没有安装 PostgreSQL 适配器 (psycopg2):

Error loading psycopg2 module: No module named psycopg2

您应该先下载正确的版本并安装:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#psycopg

更新:由于问题的格式不正确,我看不到您已经下载了它。您是否考虑了“虚拟环境安装说明”中的注释?使用 virtualenv 时,不应双击安装程序 exe。相反,您应该使用 setuptoolsdistribute将软件包安装到您的 virtualenv 中。参见 http://www.stickpeople.com/projects/python/win-psycopg/了解详情。

关于django - 在 Windows 中为 django 安装 postgresql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28926403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com