setchock setchock - 1 year ago 154
Python Question

django: How to avoid permission error on migration

I am trying to deploy a django application on a virtual server running ubuntu 16.04.

python makemigrations

leads to the following traceback, after some models and fields have been created:

Traceback (most recent call last):
File "", line 12, in <module>
File "/home/sysadmin/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/", line 353, in execute_from_command_line
File "/home/sysadmin/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/", line 345, in execute
File "/home/sysadmin/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/", 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/", line 399, in execute
output = self.handle(*args, **options)
File "/home/sysadmin/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/commands/", line 150, in handle
File "/home/sysadmin/.virtualenvs/django/local/lib/python2.7/site-packages/django/core/management/commands/", line 179, in write_migration_files
with open(writer.path, "wb") as fh:
IOError: [Errno 13] Permission denied: u'/home/sysadmin/public_html/'

I also tried:

sudo python makemigrations

But since I am using a virtual environment, I get the following error, since django is not installed system wide:

ImportError: No module named

How can I fix this error? The python path is recognized correctly and django is obviously installed in the venv.

How do I have to set the permissions for the user?


Answer Source

You need grant access for user to migrations folder:

sudo chown <your_username> <path_to_migrations_folder>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download