49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
#!/usr/bin/env python
|
|
"""Django's command-line utility for administrative tasks."""
|
|
import os
|
|
import sys
|
|
|
|
|
|
def main():
|
|
"""Run administrative tasks."""
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.dev")
|
|
if os.environ.get("DJANGO_MANAGE_BREAKPOINT", "").strip().lower() in {
|
|
"1",
|
|
"true",
|
|
"yes",
|
|
"y",
|
|
"on",
|
|
}:
|
|
breakpoint()
|
|
blocked_commands = {
|
|
"migrate",
|
|
"makemigrations",
|
|
"squashmigrations",
|
|
"sqlmigrate",
|
|
}
|
|
allow_migrations = os.environ.get("DJANGO_ALLOW_MIGRATIONS", "").strip().lower() in {
|
|
"1",
|
|
"true",
|
|
"yes",
|
|
"y",
|
|
"on",
|
|
}
|
|
if not allow_migrations and any(arg in blocked_commands for arg in sys.argv[1:]):
|
|
raise SystemExit(
|
|
"migrations 已禁用:禁止执行 migrate/makemigrations/squashmigrations/sqlmigrate。"
|
|
"如确需执行,请临时设置环境变量 DJANGO_ALLOW_MIGRATIONS=true。"
|
|
)
|
|
try:
|
|
from django.core.management import execute_from_command_line
|
|
except ImportError as exc:
|
|
raise ImportError(
|
|
"Couldn't import Django. Are you sure it's installed and "
|
|
"available on your PYTHONPATH environment variable? Did you "
|
|
"forget to activate a virtual environment?"
|
|
) from exc
|
|
execute_from_command_line(sys.argv)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|