authtoken uses South migrations - using with post-save User handler?

418 views
Skip to first unread message

Victor Hooi

unread,
Aug 18, 2013, 10:24:15 PM8/18/13
to django-res...@googlegroups.com
Hi,

I'm using Token authentication with the post-save handler as suggested in the docs:


Specifically:

@receiver(post_save, sender=Customer)
def create_auth_token(sender, instance=None, created=False, **kwargs):
    if created:
        Token.objects.create(user=instance)

I've just enabled South in my app. However, it turns out that rest_framework.authtoken uses South migrations as well.

(As an aside - why is this? I could only see a single migration version anyhow, so not sure why we're using South here?)

When I run "syncdb" for the first time, it asks to create a Django superuser - however, this now fails, because the authtoken tables aren't created yet (since ./manage migrate now handles them):

DatabaseError: relation "authtoken_token" does not exist
LINE 1: INSERT INTO "authtoken_token" ("key", "user_id", "created") ...

Now, I can just not create the user within syncdb, and create it manually after I've run ./manage migrate.

However, I'm curious what's other people are doing? Is there a better or less manual workflow for handling this?

Cheers,
Victor

Tom Christie

unread,
Aug 19, 2013, 2:18:33 AM8/19/13
to django-res...@googlegroups.com
Hi Victor,

> Now, I can just not create the user within syncdb, and create it manually after I've run ./manage migrate.


The relevant section is this:

Also note that if you're using a post_save signal to create tokens, then the first time you create the database tables, you'll need to ensure any migrations are run prior to creating any superusers. For example:

    python manage.py syncdb --noinput  # Won't create a superuser just yet, due to `--noinput`.
    python manage.py migrate
    python manage.py createsuperuser

> I could only see a single migration version anyhow, so not sure why we're using South here?

I wouldn't exactly describe REST framework as using south.
We provide south migrations for the optional authtoken app - this ensures it's possible for users to add authtokens to an existing webapp.

All the best,

  Tom

Victor Hooi

unread,
Aug 20, 2013, 11:21:17 PM8/20/13
to django-res...@googlegroups.com
Hi,

Aha, apologies Tom, I missed that part =). That makes sense then.

Another suggestion I read was to simply do:

./manage.py syncdb --all
./manage.py migrate --fake

Cheers,
Victor
Reply all
Reply to author
Forward
0 new messages