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

3

6

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?

Reliquary answered 17/2, 2015 at 21:10 Comment(4)
Why are you trying to make migrations for app in system package? If you want to contribute, you should copy code of that package into separate django project and make migrations there.Polysyllable
Good point. But I was just following the advise here python-social-auth.readthedocs.org/en/latest/configuration/…Reliquary
I think that is mistake in documentation of python-social-auth. Package should be provided with ready for use migrations.Polysyllable
Simply adding "sudo" might sort you out if you get a similar error in future, e.g., when doing schemamigrations. "sudo python manage.py ..." instead of "python manage.py ..."Alesha
V
0

As stated in your question, changing the permissions on the directories would be a solution. Yet, another way to do this is to create an isolated Python environment for your Django project using virtualenv. Or, more conveniently, the extension virtualenvwrapper.

Install the later like this:

$ pip install virtualenvwrapper

The following creates an activates a virtualenv for your project:

$ mkvirtualenv django_project
$ workon django_project

After that, you are free to install Django and Python Social Auth

$ pip install django
$ pip install python-social-auth

You will notice that all this will be installed in $HOME/.virtualenvs/django_project

This is a common, recommended practice among Python and Django users. It will solve the permission issues, as well as other dependency issues that you may run into if you use your system's Python installation for all your projects.

Note that Python Social Auth does in fact require the creation of a migration before its use in a Django project, the migration adds a related_name to the foreign key 'user' in the 'UserSocialAuth' model

Vladivostok answered 17/2, 2015 at 23:8 Comment(1)
Good advice! I have gone and set up a virtualenv now. Thank you.Reliquary
A
1

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.

Advance answered 16/9, 2015 at 19:41 Comment(1)
Good point but this solution didn't work either for me. It still goes with the system-wide / external approach on migration files :(Cadelle
V
0

As stated in your question, changing the permissions on the directories would be a solution. Yet, another way to do this is to create an isolated Python environment for your Django project using virtualenv. Or, more conveniently, the extension virtualenvwrapper.

Install the later like this:

$ pip install virtualenvwrapper

The following creates an activates a virtualenv for your project:

$ mkvirtualenv django_project
$ workon django_project

After that, you are free to install Django and Python Social Auth

$ pip install django
$ pip install python-social-auth

You will notice that all this will be installed in $HOME/.virtualenvs/django_project

This is a common, recommended practice among Python and Django users. It will solve the permission issues, as well as other dependency issues that you may run into if you use your system's Python installation for all your projects.

Note that Python Social Auth does in fact require the creation of a migration before its use in a Django project, the migration adds a related_name to the foreign key 'user' in the 'UserSocialAuth' model

Vladivostok answered 17/2, 2015 at 23:8 Comment(1)
Good advice! I have gone and set up a virtualenv now. Thank you.Reliquary
F
0

None of these answers addresses your issue, as far as I can tell. Simply installing a new application shouldn't require creation of new migration files; they should, one would expect, be shipped with the application package.

This looks like a bug or an oversight by the package author.

Famine answered 6/10, 2015 at 23:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.