Im trying to set up Django Rest Framework authtoken, From what I understand the table authtoken_token
should be created after makemigrations
and migrate
. I added rest_framework to settings.py
:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Site',
'rest_framework',
'rest_framework.authtoken',
'MySQLdb'
]
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAdminUser'
],
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
),
}
The migration commands output:
'manage.py@MySite > makemigrations Site
"C:\Program Files (x86)\JetBrains\PyCharm 2016.2\bin\runnerw.exe" C:\Python27\python.exe "C:\Program Files (x86)\JetBrains\PyCharm 2016.2\helpers\pycharm\django_manage.py" makemigrations Site "C:/Users/Eric Franzen/PycharmProjects/MySite"
No changes detected in app 'Site'
Process finished with exit code 0
manage.py@MySite > migrate Site
"C:\Program Files (x86)\JetBrains\PyCharm 2016.2\bin\runnerw.exe" C:\Python27\python.exe "C:\Program Files (x86)\JetBrains\PyCharm 2016.2\helpers\pycharm\django_manage.py" migrate Site "C:/Users/Eric Franzen/PycharmProjects/MySite"
Operations to perform:
Apply all migrations: Site
Running migrations:
No migrations to apply.
Process finished with exit code 0' If anyone has any idea why the table is not being created the information would be appreciated!
running migrate authtoken
fixed this
I was using migrate authtoken
due to a similar issue where the tables weren't being created.
But when running tests the migrations would fail, because of another migration on my app to store a Token on the superuser; manage.py test
was not running the migrations in the order I needed.
The solution in my case was to add a dependency to my app's migration that needed Token, looking like:
dependencies = [
('api', '0005_auto_20200221_2108'), # the prior migration
('authtoken', '0002_auto_20160226_1747'), # the last authtoken migration I saw in showmigrations
]
After adding the dependency the migrations run successfully, including when I run test, and I can remove migrate authtoken
from my workflow.
I'm not sure this solves the mystery of why the authtoken migrations weren't being run at all in the original scenario, but maybe it helps unstick someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With