简体   繁体   English

Django manage.py 迁移错误

[英]Django manage.py migrate error

So I am currently in a virtual environment, and when I typed the command line:所以我目前处于虚拟环境中,当我输入命令行时:

python manage.py migrate

and I encounter this problem:我遇到了这个问题:

>     Traceback (most recent call last):
>       File "manage.py", line 24, in <module>
>         execute_from_command_line(sys.argv)
>       File "C:\Users\DUCNGU~1\Desktop\HAULER~1\api\vnenv\lib\site-packages\django\core\management\__init__.py",
> line 371, in execute_from_command_line
>         utility.execute()
>       File "C:\Users\DUCNGU~1\Desktop\HAULER~1\api\vnenv\lib\site-packages\django\core\management\__init__.py",
> line 317, in execute
>         settings.INSTALLED_APPS
>       File "C:\Users\DUCNGU~1\Desktop\HAULER~1\api\vnenv\lib\site-packages\django\conf\__init__.py",
> line 56, in __getattr__
>         self._setup(name)
>       File "C:\Users\DUCNGU~1\Desktop\HAULER~1\api\vnenv\lib\site-packages\django\conf\__init__.py",
> line 43, in _setup
>         self._wrapped = Settings(settings_module)
>       File "C:\Users\DUCNGU~1\Desktop\HAULER~1\api\vnenv\lib\site-packages\django\conf\__init__.py",
> line 106, in __init__
>         mod = importlib.import_module(self.SETTINGS_MODULE)
>       File "C:\Users\DUCNGU~1\Desktop\HAULER~1\api\vnenv\lib\importlib\__init__.py",
> line 126, in import_module
>         return _bootstrap._gcd_import(name[level:], package, level)
>       File "<frozen importlib._bootstrap>", line 994, in _gcd_import
>       File "<frozen importlib._bootstrap>", line 971, in _find_and_load
>       File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
>       File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
>       File "<frozen importlib._bootstrap_external>", line 678, in exec_module
>       File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
>       File "C:\Users\Duc Nguyen\Desktop\HaulerAds\api\settings.py", line 104, in <module>
>         'PORT': int(os.getenv('POSTGRES_PORT')),
>     TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

My current Django version 2.0.3.我当前的 Django 版本 2.0.3。 I checked the python pass and I have the proper path.我检查了python pass,我有正确的路径。 Please help, thank you!请帮忙,谢谢!

You're trying to retrieve POSTGRES_POST , in the os.environ but it doesn't exist.您正在尝试在os.environ中检索POSTGRES_POST ,但它不存在。
int() can't convert NoneType . int()无法转换NoneType

If it's possible that the key does not exist in your environment.如果您的环境中可能不存在该密钥。
you can set a default value :您可以设置默认值

'PORT': int(os.getenv('POSTGRES_PORT',5432))

The second argument is the default port in case that key doesn't exist in os.environ第二个参数是默认端口,以防os.environ中不存在该键

It looks like you use PostgreSQL as a database system, but Django has trouble finding the port you use for the PostgreSQL database.看起来您使用 PostgreSQL 作为数据库系统,但 Django 无法找到您用于 PostgreSQL 数据库的端口。

You can set the parameter for the command locally executing the migrations with:您可以为在本地执行迁移的命令设置参数:

POSTGRES_PORT=5432 python manage.py migrate

or another port if you configured PostgreSQL in a different way (the default port for a PostgreSQL server is 5432, but you can of course have picked a different one yourself).或者另一个端口,如果您以不同的方式配置 PostgreSQL(PostgreSQL 服务器的默认端口是 5432,但您当然可以自己选择不同的端口)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM