Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django makemigrations with python-social-auth leads to permission denied error

After adding python social auth to my installed apps, i.e.

INSTALLED_APPS = (
    ...
    'social.apps.django_app.default',
    ...
)

and then trying a

python manage.py makemigrations

I get an unsurprising permissions error

Migrations for 'default':
  0002_auto_20150217_2053.py:
    - Alter field user on usersocialauth
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/site-packages/django/core/management  /__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
  self.execute(*args, **options.__dict__)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
  output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 124, in handle
  self.write_migration_files(changes)
File "/usr/lib/python2.7/site-packages/django/core/management/commands /makemigrations.py", line 153, in write_migration_files
  with open(writer.path, "wb") as fh:
  IOError: [Errno 13] Permission denied: u'/usr/lib/python2.7/site-packages/social/apps/django_app/default/migrations/0002_auto_20150217_2053.py'

It makes sense that I can not write to system wide package installation directories.

There are some obvious ways around this, like changing the permissions on the site-packages/social directories. However, is this the only way of doing this, or am I missing something?

like image 918
mjandrews Avatar asked Feb 17 '15 21:02

mjandrews


1 Answers

With the accepted solution above, you're effectively putting project files in your python environment. And every time you deploy to a new server, you'd have to run makemigrations to create those file(s).

How about telling makemigrations to put the social migrations inside your own project?

MIGRATION_MODULES = {
    # social.apps.django_app.default    
    'default': 'myproject.mysocial.migrations',           
}

That way, when you deploy to your server, your project is self-contained and will work without hacking your Python environment.

like image 70
Trevor Cox Avatar answered Oct 14 '22 10:10

Trevor Cox