2016-06-03 2 views
0

장고보기 기능 중 하나에서 블록 제외 시도가 있습니다.이 기능은 실패 할 경우 try 블록에 작성된 사용자 개체를 삭제합니다. 사용자를 삭제하려고하면이 오류 메시지가 나타납니다.장고에서 사용자 개체를 삭제할 수 없습니다.

OperationalError: no such table: reversion_revision 

Django 관리자도 동일한 문제가 발생합니다. 나는이 OperationalError와 비슷한 사건을 다른 사람들에게 알리는 데 문제가 있으며, 왜 그런 일이 일어나고 있는지 확신 할 수 없습니다. except 블록에서 삭제할 다른 모든 객체는 아무런 문제없이 삭제됩니다.

@csrf_exempt 
def signup(request): 
    # """Register a new account with a new org.""" 
    if request.is_ajax(): 
     if request.method == "POST": 
      form = SignUp(requestPost(request)) 

     if form.is_valid(): 
      cleaned_data = form.cleaned_data 

      email = cleaned_data['email'] 
      password = cleaned_data['password'] 
      org_name = cleaned_data['org_name'] 
      org_username = cleaned_data['org_username'] 

      if cleaned_data['token']: 
       invite_token = cleaned_data['token'] 
      else: 
       invite_token = cleaned_data['invite'] 

      try: 
       account = Account.objects.create(email=email, password=password) 
       x = email[:30] 
       userExists = User.objects.filter(username=email[:30]) 
       if not userExists: 
        if len(email) < 30: 
         user = User.objects.create_user(email, email, password) 
        else: 
         email = email[:30] 
         user = User.objects.create_user(email, email, password) 

       if invite_token: 
        if ThreadInvite.objects.filter(token=invite_token): 
         invitation = ThreadInvite.objects.get(token=invite_token) 
         thread = Thread.objects.get(id=invitation.thread.id) 
         ThreadMember.objects.create(thread=thread, account=account) 
        else: 
         invitation = OrgInvite.objects.get(token=invite_token) 
         if invitation.used: 
          raise Exception("invitation code is invalid") 
         org = Org.objects.get(id=invitation.org.id) 
         OrgMember.objects.create(org=org, account=account) 
         invitation.used = False 
         invitation.save() 
         add_to_welcome(org_id=org.id, account_id=account.id) 

       if org_username and org_name: 
        org = Org.objects.create(name=org_name, username=org_username, 
              actor=account) 
        OrgMember.objects.create(account=account, org=org) 
        Thread.objects.create(name='welcome', account=account, owner=account, org=org, 
              purpose='To welcome new members to the team.') 
        add_to_welcome(org_id=org.id, account_id=account.id) 

       login(request) 

       md = mandrill.Mandrill(settings.MANDRILL_API_KEY) 
       t = invite_token.replace(' ', '+') 
       url = "https://localhost:8000/verify/{}".format(t) 
       message = { 
        'global_merge_vars': [ 
         { 
          'name': 'VERIFICATION_URL', 
          'content': url 
         }, 
        ], 
        'to': [ 
         { 
          'email': '[email protected]', 
         }, 
        ], 
        'subject': 'Welcome to Human Link', 
       } 
       message['from_name'] = message.get('from_name', 'Humanlink') 
       message['from_email'] = message.get('from_email', 
                '[email protected]') 
       try: 
        md.messages.send_template(
         template_name='humanlink-welcome', message=message, 
         template_content=[], async=True) 
       except mandrill.Error as e: 
        logging.exception(e) 
        raise Exception(e) 

       context = { 
        'message': 'ok' 
       } 

       return composeJsonResponse(200, "", context) 

      except Exception, e: 
       logging.error(e) 
       Account.objects.filter(email=email, password=password).delete() 
       User.objects.filter(username=email[:30]).delete() 
       Org.objects.filter(name=org_name, username=org_username).delete() 

구조

├── account 
│   ├── __init__.py 
│   ├── __init__.pyc 
│   ├── admin.py 
│   ├── admin.pyc 
│   ├── apps.py 
│   ├── forms.py 
│   ├── forms.pyc 
│   ├── migrations 
│   ├── models.py 
│   ├── models.pyc 
│   ├── tests.py 
│   ├── tests.pyc 
│   ├── urls.py 
│   ├── urls.pyc 
│   ├── views.py 
│   └── views.pyc 
├── api_helpers.py 
├── api_helpers.pyc 
├── app 
│   └── components 
├── bower.json 
├── bower_components 
│   ├── angular 
│   ├── angular-animate 
│   ├── angular-bootstrap 
│   ├── angular-cookies 
│   ├── angular-messages 
│   ├── angular-sanitize 
│   ├── angular-scroll-glue 
│   ├── angular-touch 
│   ├── angular-ui-router 
│   ├── bootstrap 
│   ├── checklist-model 
│   ├── font-awesome 
│   ├── jquery 
│   ├── moment 
│   ├── pusher-websocket-iso 
│   └── underscore 
├── cron_tasks.py 
├── gulpfile.js 
├── logs 
│   └── readme.txt 
├── manage.py 
├── message 
│   ├── __init__.py 
│   ├── __init__.pyc 
│   ├── admin.py 
│   ├── admin.pyc 
│   ├── forms.py 
│   ├── forms.pyc 
│   ├── migrations 
│   ├── models.py 
│   ├── models.pyc 
│   ├── urls.py 
│   ├── urls.pyc 
│   ├── views.py 
│   └── views.pyc 
| 
├── org 
│   ├── __init__.py 
│   ├── __init__.pyc 
│   ├── admin.py 
│   ├── admin.pyc 
│   ├── forms.py 
│   ├── forms.pyc 
│   ├── migrations 
│   ├── models.py 
│   ├── models.pyc 
│   ├── tests.py 
│   ├── tests.pyc 
│   ├── urls.py 
│   ├── urls.pyc 
│   ├── views.py 
│   └── views.pyc 
├── package.json 
├── readme.txt 
├── settings 
│   ├── __init__.py 
│   ├── __init__.pyc 
│   ├── base.py 
│   ├── base.pyc 
│   ├── cron.py 
│   ├── development.py 
│   ├── development.pyc 
│   └── production.py 
├── sqlite3 
│   └── local.db 
├── stylesheets 
│   └── less 
├── templates 
│   ├── accounts 
│   ├── admin 
│   ├── dashboard 
│   ├── footer.html 
│   ├── home 
│   ├── layouts 
│   ├── nav.html 
│   ├── pages 
│   ├── settings 
│   ├── shared 
│   ├── site-alert.html 
│   └── site.html 
├── third_party 
│   ├── classytags 
│   ├── dateutil 
│   ├── django_pusher 
│   ├── itsdangerous.py 
│   ├── itsdangerous.pyc 
│   ├── mandrill.py 
│   ├── mandrill.pyc 
│   ├── mptt 
│   ├── pusher 
│   ├── requests 
│   ├── reversion 
│   ├── six.py 
│   ├── six.pyc 
│   ├── suit 
│   └── werkzeug 
├── utility.pyc 
├── webapp 
│   ├── __init__.py 
│   ├── __init__.pyc 
│   ├── static 
│   ├── urls.py 
│   ├── urls.pyc 
│   ├── views.py 
│   ├── views.pyc 
│   ├── wsgi.py 
│   └── wsgi.pyc 
└── webapp_admin 
    ├── __init__.py 
    ├── __init__.pyc 
    └── static 
+0

당신이 물어와 함께, 당신이 사용하는 것이 좋습니다 수에 걸쳐 [거래] (https://docs.djangoproject.com/en/1.9/topics/db/transactions/) 워프 너의 기능? 이는 오류가 발생했을 때 변경 사항을 롤백하여 정확히 상황을 처리하기위한 것입니다. – jstlaurent

답변

1

문제는 여기에 코드뿐만 데이터베이스 상태에 있지 않습니다. django reversion 앱을 추가 한 것 같습니다. 프로젝트에 새로운 모델이 추가됩니다.

python manage.py syncdb 

을 실행하거나 경우에 당신이 당신의 제 3 자에 대한 마이그레이션이없는 것보다 도움을 먼저 작성해야되는 앱하지 않는 경우 1.8 이상

python manage.py migrate 

업데이트

에서 그들과 함께

python manage.py makemigrations name_3rd_party_app 

타사 앱에서 마이그레이션을 만들 때는주의하십시오. makemigrations을 실행하면 타사 앱 패키지에서 이전이 생성됩니다. 그래서 그것은 당신의 코드에 없을 것입니다. 그리고 배포 한 후에 또는 다른 사용자가이 마이그레이션을 사용하지 않을 것입니다. 그래서 당신은 https://docs.djangoproject.com/en/1.9/ref/settings/#migration-modules

로 만든 마이그레이션에 대한 사용자 지정 경로를 제공 그리고 migrate

+0

흠 나는 migrate를 실행했는데 모든 것이 최신이라고합니다. "적용 할 마이그레이션이 없습니다." – JBT

+0

'python manage.py makemigrations reversion'은 어떤 것을 생성합니까? 어떤 버전의 장고와 장고 - 귀환을 사용하고 있습니까? –

+0

리 버전 앱을위한 이전 작업을 수행하고 이전 작업을 수행하는 것보다 효과적입니다. 왜 애플 리케이션을 지정하지 않고 'python manage.py makemigrations'를 수행하면 응용 프로그램 전체 마이그레이션이 가능하지 않은 이유는 확실하지 않지만 효과적입니다. 감사 !! – JBT

0

다음

./manage.py migrate

아니면 그냥 삭제

./manage.py makemigrations revisions

를 실행 해 실행해야 db 파일 및 시작 실제 문제를 넘어

./manage.py migrate

관련 문제