Django manage.py迁移错误

时间:2018-05-16 20:19:04

标签: python django

所以我目前处于虚拟环境中,当我输入命令行时:

python manage.py migrate

我遇到了这个问题:

>     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'

我目前的Django版本2.0.3。我检查了python传球,我有正确的路径。 请帮忙,谢谢!

2 个答案:

答案 0 :(得分:3)

您正试图在POSTGRES_POST中检索os.environ,但它不存在 int()无法转换NoneType

如果您的环境中可能没有该密钥 您可以设置默认值

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

如果os.environ

中不存在该键,则第二个参数是默认端口

答案 1 :(得分:1)

看起来你使用PostgreSQL作为数据库系统,但是Django很难找到你用于PostgreSQL数据库的端口。

您可以使用以下命令在本地执行迁移的命令中设置参数:

POSTGRES_PORT=5432 python manage.py migrate

或其他端口,如果您以不同的方式配置PostgreSQL(PostgreSQL服务器的默认端口是5432,但您当然可以自己选择不同的端口)。