updatedb.py 724 B

1234567891011121314151617
  1. # Copyright: (c) OpenSpug Organization. https://github.com/openspug/spug
  2. # Copyright: (c) <spug.dev@gmail.com>
  3. # Released under the AGPL-3.0 License.
  4. from django.core.management.base import BaseCommand
  5. from django.core.management import execute_from_command_line
  6. from django.conf import settings
  7. class Command(BaseCommand):
  8. help = '初始化/更新数据库'
  9. def handle(self, *args, **options):
  10. args = ['manage.py', 'makemigrations']
  11. apps = [x.split('.')[-1] for x in settings.INSTALLED_APPS if x.startswith('apps.')]
  12. execute_from_command_line(args + apps)
  13. execute_from_command_line(['manage.py', 'migrate'])
  14. self.stdout.write(self.style.SUCCESS('初始化/更新成功'))