Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 在服务器运行时进行迁移或迁移_Django - Fatal编程技术网

Django 在服务器运行时进行迁移或迁移

Django 在服务器运行时进行迁移或迁移,django,Django,我想知道在django中我们如何处理数据库迁移,而该站点正在生产中,就像在开发时一样,我们停止服务器,然后对数据库进行更改,然后重新运行服务器。我认为这可能是一个愚蠢的问题,但我自己正在学习,无法理解。谢谢您提前。您可以使用ssh连接到服务器并运行命令进行迁移而不停止服务器,完成后重新启动服务器 python manage.py makemigrations 然后 python manage.py migrate 然后重新启动服务器 python manage.py makemigratio

我想知道在django中我们如何处理数据库迁移,而该站点正在生产中,就像在开发时一样,我们停止服务器,然后对数据库进行更改,然后重新运行服务器。我认为这可能是一个愚蠢的问题,但我自己正在学习,无法理解。谢谢您提前。您可以使用ssh连接到服务器并运行命令进行迁移而不停止服务器,完成后重新启动服务器

python manage.py makemigrations
然后

python manage.py migrate
然后重新启动服务器

python manage.py makemigrations
例如:对于nginx和gunicorn

sudo service gunicorn restart
sudo service nginx restart

你想弄明白什么?为什么要停止服务器?就像在powershell中一样,我无法运行python manage.py进行迁移,除非我停止服务器,然后执行run my commands并再次运行服务器。您首先运行的是服务器吗?您应该在开发中运行
makemigrations
,然后将迁移文件推送到生产环境中。在生产过程中,您需要更新代码(包括新的迁移),运行
migrate
,然后重新启动服务器。