ฉันติดอยู่กับปัญหาคอขวดซึ่งฉันพยายามแก้ไขโดยใช้เอกสารอย่างเป็นทางการและคำตอบอื่น ๆ ที่นี่ใน stackoverflow แต่ก็ยังไม่สามารถสร้าง django superuser โดยทางโปรแกรมในสภาพแวดล้อมของฝักถั่ว
สถานะปัจจุบัน - ก. แอปพลิเคชันได้รับการปรับใช้อย่างราบรื่น และฉันสามารถเข้าถึงฐานข้อมูลจากแอปพลิเคชัน UI ของฉันได้ โดยพื้นฐานแล้วรายการกำลังถูกสร้างขึ้นในตารางอื่นที่ฉันมีในแอปพลิเคชัน
ฉันพยายามสร้าง superuser อย่างไร -
ก. โดยการส่งคำสั่งคอนเทนเนอร์ -
ตัวเลือกที่ 1-
container_commands:
01_migrate:
command: "django-admin.py migrate"
leader_only: true
02_collectstatic:
command: "django-admin.py collectstatic --noinput"
commands:
super_user:
command: "source /opt/python/run/venv/bin/activate && python <appname>/createuser.py"
leader_only: true
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "<Appname>.settings"
PYTHONPATH: "/opt/python/current/app:$PYTHONPATH"
ในบันทึก - ฉันไม่เห็นว่ามันพยายามเรียกใช้คำสั่งที่กำหนดเอง
ตัวเลือก 2 -
container_commands:
01_migrate:
command: "django-admin.py migrate"
leader_only: true
02_collectstatic:
command: "django-admin.py collectstatic --noinput"
03_createsuperuser:
command: "source /opt/python/run/venv/bin/activate && django-admin.py createsuperuser"
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "<appname>.settings"
PYTHONPATH: "/opt/python/current/app:$PYTHONPATH"
สำหรับสิ่งนี้ ฉันได้สร้างไฟล์ createsuperuser.py ภายใต้ /management/commands/ ตามโครงสร้างของ init.py ในทั้งสองโฟลเดอร์และหนึ่ง createsuperuser.py ภายใต้คำสั่ง -
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
class Command(BaseCommand):
def handle(self, *args, **options):
if not User.objects.filter(username="admin").exists():
User.objects.create_superuser("admin", "[email protected]", "admin")
เกี่ยวกับเรื่องนี้ ฉันได้รับข้อความต่อไปนี้จากบันทึก -
Superuser creation skipped due to not running in a TTY. You can run `manage.py createsuperuser` in your project to create one manually.
คำถามของฉันคือ -
เหตุใดฉันจึงไม่สามารถสร้าง superuser จากบรรทัดคำสั่งของ env เสมือนของฉันได้ โดยที่ฉันได้รับข้อความเช่นนี้ -
Raise ImproperlyConfigured("settings.DATABASES is improperly configuration. " django.core.Exceptions.ImproperlyConfigured: settings.DATABASES is improperly configuration. Please enter the ENGINE value. ตรวจสอบเอกสารการตั้งค่าสำหรับรายละเอียดเพิ่มเติม
ค่อนข้างแปลกเมื่อพิจารณาว่าคำสั่ง makemigrations ทำงานได้ดี
และเมื่อฉันสะท้อน $DJANGO_SETTINGS_MODULE ฉันจะได้รับการตั้งค่าที่ถูกต้อง
appname.settings
แจ้งให้เราทราบว่าฉันผิดพลาดตรงไหนในการสร้างสิ่ง superuser?