Permission denied to create migration folder in Django app in vagrant

3k views Asked by At

I am trying to upgrade to Django 1.8 from 1.4

I tried to run the following command in vagrant environment

$ python manage.py makemigrations [app_name]

and got this error

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'

Ran the command after logging into the app via vagrant ssh [app] command. Then setup the virtual env and then this happens.

2

There are 2 answers

0
R4V On

you should be login as admin or root to your computer. If you not sure, try using sudo command on your console/terminal:

sudo python manage.py makemigrations [app_name]

0
Logic1 On

You don't have to use sudo or be root to make the migrations work.

I think sorl.thumbnail was trying to write it's migrations to a protected folder (Python site-packages perhaps?) which made things not very portable.

So to overcome the issue first create a directory in your project called "sorl_thumbnail" then include a blank __init __.py file.

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

finally add these lines somewhere in settings.py:

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

Thats it!

Now you should be able to run:

makemigrations thumbnail
migrate thumbnail

The migrations should now be found in your local project's "sorl_thumbnail/migrations" folder.