Support custom User.db_table in TokenAuthentication migration. by lucaswiman · Pull Request #2479 · encode/django-rest-framework (original) (raw)

This pull request handles the somewhat special case of using a custom user model with a custom db_table attribute. When migrating a pre-existing database that was using the auth.User model, one guide for doing so recommends creating a custom user table where db_table = 'auth_user' so that few database migrations are required.

This pull request updates the Meta parameters passed for the custom user model to include the db_table from the real settings.AUTH_USER_MODEL model.

Without this change, using a custom db_table attribute leads to errors like the following:

FATAL ERROR - The following SQL query failed: ALTER TABLE "authtoken_token" ADD CONSTRAINT "user_id_refs_id_79b40daa" FOREIGN KEY ("user_id") REFERENCES "custom_user_user" ("id") DEFERRABLE INITIALLY DEFERRED;
The error was: relation "custom_user_user" does not exist