【解決方案】Django報錯:TypeError: allow_migrate() got an unexpected keyword argument 'model_name'

參考以下鏈接設置django支持多數據庫時,遇到Django報錯:TypeError: allow_migrate() got an unexpected keyword argument 'model_name'

https://www.cnblogs.com/dreamer-fish/p/5469141.html

以下爲解決方案:

I meet the same problem when i move from 1.6.* to 1.10.Finally i found the problem cause by the DATABASE_ROUTERS

the old version i write like this

class OnlineRouter(object):
    # ... 
    def allow_migrate(self, db, model):
        if db == 'myonline':
            return model._meta.app_label == 'online'
        elif model._meta.app_label == 'online':
            return False
        return None

it work by rewrite like this

class OnlineRouter(object):
    # ... 
    def allow_migrate(self, db, app_label, model_name=None, **hints):
        if db == 'my_online':
            return app_label == 'online'
        elif app_label == 'online':
            return False
        return None

more detail see https://docs.djangoproject.com/en/1.10/topics/db/multi-db/#an-example

 

原文:https://stackoverflow.com/questions/39282860/django-typeerror-allow-migrate-got-an-unexpected-keyword-argument-model-name

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章