我正在尝试在运行ubuntu 16.04的虚拟服务器上部署django应用程序。
python manage.py makemigrations
在创建了一些模型和字段后,会导致以下回溯:
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/home/sysadmin/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/sysadmin/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/sysadmin/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/sysadmin/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/sysadmin/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 150, in handle
self.write_migration_files(changes)
File "/home/sysadmin/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 179, in write_migration_files
with open(writer.path, "wb") as fh:
IOError: [Errno 13] Permission denied: u'/home/sysadmin/public_html/aegee-stuttgart.org/aegeewww/migrations/0001_initial.py'
我也尝试过:
sudo python manage.py makemigrations
但由于我使用的是虚拟环境,因此django未在系统范围内安装,因此出现以下错误:
ImportError: No module named django.core.management
如何修复此错误? python路径被正确识别,django显然安装在venv中。
如何为用户设置权限?
谢谢!
答案 0 :(得分:4)
您需要用户对迁移文件夹的授予访问权限:
sudo chown <your_username> <path_to_migrations_folder>
答案 1 :(得分:1)
该目录应归当前用户所有,以对其进行更改。
用于即时解决方案:
尝试:sudo python3 manage.py makemigrations
也尝试通过改变弦
sudo chown owner_name foldername(or)dir
例如:sudo chown ubuntu db.sqlite3
在相应目录中。
使用以下方法进行检查:
ls -la
显示当前目录中文件的权限。
如果没有解决办法,请尝试更改文件的读/写权限:
sudo chmod permission_no dir_name
Permission_no 6644或777都可以正常工作。
例如:sudo chmod 777 db.sqlite3