2010-11-14 16 views
5

मैं django 1.2 का उपयोग कर रहा हूं, और मुझे अपने प्रोजेक्ट पर दूसरा डेटाबेस सेट करना पड़ा। जैसे ही मैंने अपना प्रोजेक्ट पर दूसरा कनेक्शन और राउटर सेट किया, मेरे सभी टेस्ट केस जो उस दूसरे डेटाबेस का भी जिक्र नहीं कर रहे हैं, विफल होने लगते हैं। एप्लिकेशन चलाना ठीक काम करता है, syncdb ठीक काम करता है, केवल परीक्षण (इकाई परीक्षण) है कि मेरे पास समस्याएं हैं।क्या django परीक्षण ढांचे द्वारा समर्थित कई डेटाबेस हैं?

यह मेरे लिए प्रतीत होता है कि दूसरा डेटाबेस कभी नहीं बनाई गई है, और यहां तक ​​कि अगर मुझे लगता है कि मैन्युअल रूप (test_mydbname) बना यह ऐसा न करने पर रहता है।

क्या यह समर्थित है?

+0

http://docs.djangoproject.com/en/dev/topics/testing/?from=olddocs#testing-master-slave-configurations http://docs.djangoproject.com/en/dev/topics/testing /? = olddocs # बहु डेटाबेस-समर्थन से – Thomas

उत्तर

1

मुझे एक डिफ़ॉल्ट राउटर जोड़ना पड़ा, फिर मेरे परीक्षण फिर से काम करना शुरू कर दिया। परीक्षण परिदृश्य में लगता है, django को "डिफ़ॉल्ट" डेटाबेस के बारे में पता नहीं है। सभी infos, परीक्षण डाटाबेस रचना क्रम सहित: https://docs.djangoproject.com/en/dev/topics/testing/advanced/#tests-and-multiple-databases

इसे मेरा डिफ़ॉल्ट रूटर (django 1.7, allow_relation और allow_migrate बारे में इतना यकीन नहीं है, हालांकि

class DefaultRouter(object): 
    """ 
    A router for the default db. add last in settings 
    """ 

    db_label = 'default' 

    def db_for_read(self, model, **hints): 
     return self.db_label 

    def db_for_write(self, model, **hints): 
     return self.db_label 

    def allow_relation(self, obj1, obj2, **hints): 
     return True 

    def allow_migrate(self, db, app_label, model=None, **hints): 
     return True 

और settings.py में:

DATABASE_ROUTERS = ['otherapp.dbrouter.CustomDbRouter', 'project.dbrouter.DefaultRouter'] 
संबंधित मुद्दे