gpt4 book ai didi

python - 在 vagrant 的 Django 应用程序中创建迁移文件夹的权限被拒绝

转载 作者:行者123 更新时间:2023-12-01 04:40:11 25 4
gpt4 key购买 nike

我正在尝试从 1.4 升级到 Django 1.8

我尝试在vagrant环境中运行以下命令

$ python manage.py makemigrations [app_name]

并收到此错误

Traceback (most recent call last): File "manage.py", line 9, in execute_from_command_line(sys.argv) File "/srv/www/[project]/shared/env/local/lib/python2.7/site-packages/django/core/management/init.py", line 338, in execute_from_command_line utility.execute() File "/srv/www/[project]/shared/env/local/lib/python2.7/site-packages/django/core/management/init.py", line 330, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/srv/www/[project/shared/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv self.execute(*args, **cmd_options) File "/srv/www/[project]/shared/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute output = self.handle(*args, **options) File "/srv/www/[project]/shared/env/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 143, in handle self.write_migration_files(changes) File "/srv/www/[project]/shared/env/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 165, in write_migration_files os.mkdir(migrations_directory) OSError: [Errno 13] Permission denied: '/vagrant/code/[project]/[app]/migrations'

通过 vagrant ssh [app] 命令登录应用程序后运行命令。然后设置虚拟环境,然后就会发生这种情况。

最佳答案

您不必使用 sudo 或成为 root 即可进行迁移。

我认为 sorl.thumbnail 试图将其迁移写入 protected 文件夹(也许是 Python 站点包?),这使得事情不太可移植。

因此,为了解决这个问题,首先在项目中创建一个名为“sorl_thumbnail”的目录,然后包含一个空白的 __init __.py 文件。

MyProject
|_MyApp1
| |_migrations
| |___init__.py
|
|_sorl_thumbnail
|___init__.py

最后在 settings.py 中的某处添加这些行:

MIGRATION_MODULES = {
'thumbnail': 'sorl_thumbnail.migrations',
}

就是这样!

现在您应该能够运行:

makemigrations thumbnail
migrate thumbnail

现在应该可以在本地项目的“sorl_thumbnail/migrations”文件夹中找到迁移。

关于python - 在 vagrant 的 Django 应用程序中创建迁移文件夹的权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30874885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com