Opened 6 years ago
Last modified 2 years ago
#29564 closed Bug
Executing createsuperuser with non-default database. — at Initial Version
Reported by: | Oleg Żero | Owned by: | nobody |
---|---|---|---|
Component: | contrib.auth | Version: | 2.0 |
Severity: | Normal | Keywords: | multiple database router createsuperuser |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hello!
I tried to use a different, non-default designated database for storing (auth, admin, contenttype, session), named 'users', another one for that is application-specific 'application' and 'default' is then used for everything else, like this:
... DATABASES = { 'default': dj_database_url.parse(os.environ['DATABASE_OPS_URL'], conn_max_age=500), # for everything else... 'users': dj_database_url.parse(os.environ['DATABASE_USR_URL'], conn_max_age=500), # for auth-stuff 'application': dj_database_url.parse(os.environ['DATABSE_APP_URL'], conn_max_age=500), # for app } DATABASE_ROUTERS = ['myapplication.routers.AuthRouter']
Following your example https://docs.djangoproject.com/en/2.0/topics/db/multi-db/#topics-db-multi-db-routing,
I created a router.py, in which I replicated your code.
Then:
$ ./manage.py migrate $ ./manage.py migrate --database=users $ ./manage.py migrate --database=application
Works fine. I verified the database content, and yes, the tables are created in 'users'.
However, when executing:
$ ./manage.py createsuperuser
I get prompted to define the name, but just after I hit enter, I get a django.db.utils.ProgrammingError: relation "auth_user" does not exist
LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "auth_user...
...and django fails to initialize that user.
The only way I can get it to work, is when the 'users' database matches the 'default' one.
How do I work around it? Is it a bug?
Thank you very much in advance!