Django: OperationalError on initial syncdb when a reusable south app has user_post_save signal

StackOverflow https://stackoverflow.com/questions/22311536

  •  12-06-2023
  •  | 
  •  

문제

I have an app which integrates a forked version of django-invitation where it has modified the original model. Therefore It needs to use south to migrate existing databases.

The problem:

If i do a fresh install of my app with a new database, when the initial syncdb occurs and the superuser is created the django-invitation app receives the user_post_save signal and tries to create an invitation_user... Since it is a south app, it's database tables have not been constructed which of course triggers a database error.

What is the recommended approach to dealing with this issue?

Idea 1) Check if the table exists in the data base prior o trying to save, but this would require the extra database hit every time a user is created.

Idea 2)

Try: 
    invitation_user.save() 
except:
    from django.db import connection
    connection.close()

Is there has to be a better way...

도움이 되었습니까?

해결책

Since nobody has chimed in I guess the best thing to do is go with my original idea#2:

Try: 
    #code that could fail on new database creation here
except OperationalError:
    from django.db import connection
    connection.close()

I have been testing it since my original question and it seems to work great.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top