Python django中Postgresql数据库安装存在问题
我对dajngo中的postgresql数据库有问题。当我运行python-mpipinstallpsycopg2命令时,它可以工作。因此,我运行命令python manage.py makemigrations时,遇到了以下问题: 但当我运行命令pip freeze时,结果如下: Django==2.2.6 psycopg2==2.8.4 pytz==2019.3 sqlparse==0.3.0 这是我的settings.py文件数据库: 这是我的配置: Windows 10 64位 -Django 2.2.6 -Psycopg2 2.8.4 -Postgresql 12 -pip 19.3.1 C:\XXX\PostgreSQL\12\bin在我的路径中。 我使用Visual Studio代码IDE。0。安装迷你康达 或者去 下载miniconda 32或64位的版本?然后安装它。 一,。康达基本用法 非常简单: 列出所有可用的conda环境:conda环境列表 创建新的conda环境:conda create-name 输入conda env:conda activate或source activate 停用conda环境:conda停用或源停用 进入conda env后: 安装程序包:conda安装主要使用-c和 最受欢迎的回购协议是:康达福吉、巨蟒或生物信息学中的bioconda非常最新 通过以下方式删除包:conda remove 列出此环境中的所有包:conda list 所以你可以看到所有这些都和virtualenv非常相似 二,。搜索conda包安装命令 只需谷歌康达安装,然后你会发现大部分的蟒蛇网站 使用正确的命令-c,不管是什么,对于哪个操作系统和版本 然而,康达软件包大多不是一流的。皮普更为顶尖。 您可以通过将pip安装到conda环境中来解决此问题 三,。创建环境并安装python和pip 将安装以下新软件包:Python django中Postgresql数据库安装存在问题,python,django,postgresql,psycopg2,Python,Django,Postgresql,Psycopg2,我对dajngo中的postgresql数据库有问题。当我运行python-mpipinstallpsycopg2命令时,它可以工作。因此,我运行命令python manage.py makemigrations时,遇到了以下问题: 但当我运行命令pip freeze时,结果如下: Django==2.2.6 psycopg2==2.8.4 pytz==2019.3 sqlparse==0.3.0 这是我的settings.py文件数据库: 这是我的配置: Windows 10 64位 -
_libgcc_mutex: 0.1-main
ca-certificates: 2018.03.07-0
certifi: 2018.11.29-py37_0
libedit: 3.1.20170329-h6b74fdf_2
libffi: 3.2.1-h97ff0df_4
libgcc-ng: 8.2.0-h9268252_1
libstdcxx-ng: 8.2.0-h9268252_1
ncurses: 6.1-he6710b0_1
openssl: 1.1.1a-h7b6447c_0
pip: 18.1-py37_0
python: 3.7.1-h0371630_7
readline: 7.0-h7b6447c_5
setuptools: 40.6.3-py37_0
sqlite: 3.26.0-h7b6447c_0
tk: 8.6.8-hbc83047_0
wheel: 0.32.3-py37_0
xz: 5.2.4-h14c3975_4
zlib: 1.2.11-h7b6447c_3
因此,它会使用python自动安装pip。
因此,在本次安装之后,您还需要安装到中的pip
康达环境
我所做的是尝试找到所需软件包的安装。
只有当我无法使用conda获得所需的版本或软件包时,
我在这个环境中切换到pip安装。
由于Pip在本地安装到虚拟环境中,因此将在本地安装
一切都进入康达环境。
顺便说一句,我意识到,也许你在开始时使用了一个全局pip和
在你的虚拟环境中一点都没有?也许这就是问题所在
四,。将postgresql安装到conda环境中
进入conda env后,执行以下操作:
conda install -y -c conda-forge postgresql
五,。在django中设置postgresql
我使用的来源是:[这个][和[这个][
django使用的数据库是一个内部数据库
首先初始化外部基本数据库:
initdb -D db_djangogirls # this is a database physically in your folder
# start postgres by using this db
postgres -D db_djangogirls & # runs postgres
# press RET to send it to background!
在该状态下-创建非超级用户
createuser --encrypted --pwprompt djangogirls
# pass '<yourpassword>' 2x
这是你需要告诉django的数据库
此用户和此密码
因此,您可以设置settings.py:
并且做:
python manage.py migrate
如果事情不顺利,你必须杀死博士后才能重新开始
# In linux, you monitor servers by:
ps aux | grep postgres
# the line with databasename - the first one - that number you use to kill the process
kill <number>
# e.g. the line
# <yourname> 30453 0.0 0.0 14760 2780 pts/6 S+ 08:36 0:00 grep --color=auto postgres
评论不是为了进行深入讨论;这段对话一直都是。这有点复杂,因为教程没有涵盖postgresql在本地安装到conda中的情况-这是我在它工作之前必须处理的部分。但我在下面详细描述了我所做的步骤。也许某些顺序并不正确-但我所理解的是,有一个外部数据库和一个内部数据库。你试过我第一次写的方式吗?
createdb --owner=djangogirls djangogirls_db # this is the name of the inner database and that name of the inner you have to use in `settings.py`!
nano mysite/settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'djangogirls_db',
'USER': 'djangogirls',
'PASSWORD': 'djangogirls',
'HOST': 'localhost',
'PORT': '',
}
}
python manage.py migrate
# In linux, you monitor servers by:
ps aux | grep postgres
# the line with databasename - the first one - that number you use to kill the process
kill <number>
# e.g. the line
# <yourname> 30453 0.0 0.0 14760 2780 pts/6 S+ 08:36 0:00 grep --color=auto postgres
pg_ctl -D db_djangogirls -l logfile start