From 861a1af622436bccc9d1199da2e9e24b2c36fd5d Mon Sep 17 00:00:00 2001 From: vapao Date: Fri, 3 Jul 2020 15:53:08 +0800 Subject: [PATCH] =?UTF-8?q?A=20=E6=B7=BB=E5=8A=A0updatedb=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E4=BB=A3=E6=9B=BFinitdb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apps/account/management/commands/initdb.py | 1 + .../account/management/commands/updatedb.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 spug_api/apps/account/management/commands/updatedb.py diff --git a/spug_api/apps/account/management/commands/initdb.py b/spug_api/apps/account/management/commands/initdb.py index 345a918..c943ccc 100644 --- a/spug_api/apps/account/management/commands/initdb.py +++ b/spug_api/apps/account/management/commands/initdb.py @@ -15,3 +15,4 @@ class Command(BaseCommand): execute_from_command_line(args + apps) execute_from_command_line(['manage.py', 'migrate']) self.stdout.write(self.style.SUCCESS('初始化成功')) + self.stdout.write(self.style.WARNING('废弃警告,v2.4.0之后将会移除该命令,请使用 python manage.py updatedb 来代替!')) diff --git a/spug_api/apps/account/management/commands/updatedb.py b/spug_api/apps/account/management/commands/updatedb.py new file mode 100644 index 0000000..15df476 --- /dev/null +++ b/spug_api/apps/account/management/commands/updatedb.py @@ -0,0 +1,17 @@ +# Copyright: (c) OpenSpug Organization. https://github.com/openspug/spug +# Copyright: (c) +# Released under the AGPL-3.0 License. +from django.core.management.base import BaseCommand +from django.core.management import execute_from_command_line +from django.conf import settings + + +class Command(BaseCommand): + help = '初始化/更新数据库' + + def handle(self, *args, **options): + args = ['manage.py', 'makemigrations'] + apps = [x.split('.')[-1] for x in settings.INSTALLED_APPS if x.startswith('apps.')] + execute_from_command_line(args + apps) + execute_from_command_line(['manage.py', 'migrate']) + self.stdout.write(self.style.SUCCESS('初始化/更新成功'))