我一直在尝试使用cookiecutter-django在本地设置一个新的django项目。我已经按照文档进行了操作,但在尝试运行python manage.py migrate
时遇到了错误。
错误回溯。
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site- packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/ubuntu/lasbrisas_project/django_condominios/config/settings/local.py", line 11, in <module>
from .common import * # noqa
File "/home/ubuntu/lasbrisas_project/django_condominios/config/settings/common.py", line 102, in <module>
'default': env.db('DATABASE_URL', default='postgres:///django_condominios'),
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/environ/environ.py", line 180, in db_url
return self.db_url_config(self.get_value(var, default=default), engine=engine)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/environ/environ.py", line 371, in db_url_config
'PORT': _cast_int(url.port),
File "/usr/lib/python3.4/urllib/parse.py", line 156, in port
port = int(port, 10)
ValueError: invalid literal for int() with base 10: 'jd#uhUhey385'
在设置项目时,我真的不知道自己做错了什么,如果你查看我采取的步骤并帮助我找出遗漏的内容,我将不胜感激。
使用cookiecutter-django设置项目的步骤:
pip,virtualenv,PostrgreSQL已安装
pip install cookiecutter
cookiecutter https://github.com/pydanny/cookiecutter-django
virtualenv -p /usr/bin/python3 venv
source venv/bin/activate/
cd intoprojectfolder
sudo ./install_os_dependencies.sh install
但是./install_os_dependencies.sh不在projectroot中,在实用程序/中找到文件
cd utility
sudo ./install_os_dependencies.sh install
pip install -r requirements/local.txt
sudo su - postgres
psql
CREATE DATABASE myproject;
CREATE USER myprojectuser WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;
\q
mv env.example .env
export DATABASE_URL=postgres://myprojectuser:myprojectuserdbpassword@127.0.0.1:5432/myproject
python manage.py migrate
在那之后,当我得到追溯时,可能会出现什么问题?文档不再显示信息,迁移应该有效。
答案 0 :(得分:2)
Cookiecutter使用项目名称的slug作为您要使用的开发db的名称。您需要自己创建数据库。
来自您的stacktrace的是您在settings.py文件中提供问题的行:
File "/home/ubuntu/lasbrisas_project/django_condominios/config/settings/common.py", line 102, in <module>'default': env.db('DATABASE_URL', default='postgres:///django_condominios'),
它希望找到一个名为 django_condominios 的数据库。
您可以通过运行
来解决此问题createdb django_condominios
你应该很好地进行迁移。