Reputation: 61
I'm trying to develop an Django Application which uses Google API for authentication. Everything seems to work fine, however after login I got this error: no such table: social_auth_usersocialauth and I have no idea how to solve it.
Is there anyone who already had this same problem that could help me?
I appreciate any help, thanks.
Upvotes: 5
Views: 3690
Reputation: 69
For me the issue was that I was missing social_django
in INSTALLED_APPS
in settings.py
.
Ref. link to official docs.
Upvotes: 2
Reputation: 56
Same problem with Django 3.0.3 when integrating with Auth0, started app from scratch.
Got it to work using the answer above; since I was developing this code a while now, did not want to start from scratch. For "New Code," have to say that simply downgrading to older version and doing "python3 manage.py migrate" won't always do. Django 3.0.3 models.ForeignKey(...) works differently and old version of the social app won't work.
Got this work with Django 3.0.3 and social-auth-app-django 3.1. The goal is to generate all the tables using Django manage.py script and models in the install packages.
Problem encountered:
settings.py
needs to be modified for old app to generate tables using python migration tool.
in the old app, model is incompatible with new version of django, this is what I got: TypeError: __init__() missing 1 required positional argument: 'on_delete'
It is obvious that latest version of social app lib does not generate the tables it requires.
Solution:
Basically the steps Renan Fonteles described in his post here are sound, his post helped. Temporarily downgrading to python-social-auth==0.2.21 works. To solve the problem you can take these steps:
Remove all the site packages from the venv, and make a new venv as in: $ python3 -m venv .
install all the requirements as before, but instead of latest version of social-auth-app-django
run:
$ pip install python-social-auth==0.2.21
so remove the social-auth-app-django from requirements.txt
at this point, for django 3.0.3, manually edit the model for the app in .../site-packages
, models.ForeignKey
has to have an additional argument.
${DJANGO_ENV_DIR}/lib/python3.7/site-packages$ find . -name "*.py" -exec grep -Hn 'models.Foreign' {} \;
./social/apps/django_app/default/migrations/0002_add_related_name.py:25: field=models.ForeignKey(related_name='social_auth', to=USER_MODEL)
./social/apps/django_app/default/migrations/0001_initial.py:97: ('user', models.ForeignKey(
./social/apps/django_app/default/models.py:33: user = models.ForeignKey(USER_MODEL, related_name='social_auth')
add , on_delete=models.CASCADE
as the last argument to models.ForeignKey
call in each file that came up above. Because, models.ForeignKey
has to have additional argument:
... = models.ForeignKey(..., on_delete=models.CASCADE)
manage.py
won't install the 'social_django'
app since the package downgrading to in this step does not have this app, the olden app is: 'social.apps.django_app.default'
.
Change the 'social_django'
to the 'social.apps.django_app.default'
in settings.py INSTALLED_APPS = [...]
section, or add the former to the section.
settings.py DATABASES ...
can have a section like this:
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3_user_authentication'),
},
Run: python manage.py migrate
, provided settings.py
has databases for your authentication app set up as above it should make you the tables you need.
Upgrade to latest version of social-auth-app-django
$ pip uninstall python-social-auth==0.2.21
$ pip install social-auth-app-django
now you can put the social-auth-app-django
back into requirements.txt
Note: You can't really call python-social-auth==0.2.21
a dependency, to generate tables you need to add it to INSTALLED_APPS, at the end you have to remove it from INSTALLED_APPS.
Change the app back from 'social.apps.django_app.default'
to 'social_django'
Now run python manage.py migrate
again.
These steps make sqlite db file with the table you later need for the app to work, you might want to save / backup this dbfile if you ever do migrations on this database. The 'social_django'
app will work now if you have all the rest of the settings.py correct.
These posts helped a lot to get the app to work:
Eventually, I got the authentication to work with Auth0 and Google. Hopping for a fix to social-auth-app-django
to make this answer obsolete. The latest package should generate the schema if app is being developed from scratch, there should be no need to downgrade the social app export tables from it.
Upvotes: 0
Reputation: 10273
The problem is, python-social-auth
is deprecated as of December 2016.
Migrating existing projects
According to the migration instructions here:
pip install python-social-auth==0.2.21
python manage.py migrate
pip install social-auth-app-django
python manage.py migrate
pip uninstall python-social-auth
New projects
pip install python-social-auth==0.2.21
pip install social-auth-app-django
python manage.py migrate
pip uninstall python-social-auth
Upvotes: 3
Reputation: 61
I solved the problem. It seems that python-social-auth has some problems with migrations.
At least in my case, the last version of python-social-auth could not properly migrate the database.
Upvotes: 1
Reputation: 3223
It looks like you've installed one of the social auth apps but haven't migrated your database since then.
Try:
python manage.py migrate
Upvotes: 0