问题
I'm working on a multi tenant app using django-tenant-schema(and postgresql). Now as soon as the new schema is getting created, I'm using the call_command to create a superuser. I also thought of the option of using signal post_migrate.
My doubt is how can I auto create a superuser without typing the password in shell. The use case is as soon as the user registers for his/her schema, a superuser is generated and the user logs in with the superuser username and password and can change the password thereafter.
I'm using the following to call the createsuperuser command:
call_command('createsuperuser', schema_name=self.schema_name, username='admin', email='admin@admin.com')
One way to solve the issue is to change Django's createsuperuser.py
file and provide a password over there automatically, buts thats not an acceptable route, ie cahnging the source code for some use case. Could I please request for some better methods
回答1:
you can "prepare" password for new superuser and pass md5 value to bash:
a=# select md5('some password'||'test');;
md5
----------------------------------
d5b3eb515b64edf295b2ee9062946d24
(1 row)
a=# create user test superuser password 'md5d5b3eb515b64edf295b2ee9062946d24';
CREATE ROLE
so you can use d5b3eb515b64edf295b2ee9062946d24
in bash, saving password somewhere else?..
来源:https://stackoverflow.com/questions/38019532/autocreate-superuser-with-each-schema-django