【问题标题】:Adding groups to Jenkins without breaking migrations?在不中断迁移的情况下向 Jenkins 添加组?
【发布时间】:2014-10-28 18:36:56
【问题描述】:

在我正在编写的一个 django 项目中,我需要一个(现在,我以后可能想要更多)组,该组应该在服务器运行时自动设置。我通过子类化 AppConfig 来完成这项工作,但这似乎破坏了迁移。

在库/init.py 我有

default_app_config = 'thelibrary.apps.LibraryConfig'

我在 thelibrary/apps.py 中有以下内容

"""
    Handles initial configuration and site wide settings
"""

from django.db import models

from django.contrib.auth.models import Group, User


from django.apps import AppConfig

"""
Group and permission configuration
"""

#Project Leaders

class LibraryConfig(AppConfig):

    name = 'thelibrary'

    def ready(self):
        verbose_name = 'The Library'

        try:
            lead = Group.objects.get(name='lead')

        except: 
            Group.objects.create(name='lead')

这将毫无问题地设置组“领导”,只要我有一个不需要迁移的现有数据库,它就可以完美地工作。但是,当我尝试创建初始数据库时,我必须注释掉我的组创建,因为此时没有可用的数据库。

我能做些什么来解决这个问题?有没有更好的方法在项目刚开始时创建组?

【问题讨论】:

    标签: python django django-authentication


    【解决方案1】:

    我太傻了,我应该再试一次,除了。

    class LibraryConfig(AppConfig):
    
        name = 'thelibrary'
    
        def ready(self):
            verbose_name = 'The Library'
    
            try:
                lead = Group.objects.get(name='lead')
    
            except: 
                try:
                    Group.objects.create(name='lead')
                except:
                    print "Failed"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-02
      • 2012-07-12
      • 2015-11-06
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多