2016-09-02 9 views
3

私はDjangoプロジェクトを新しいサーバにコピーし、環境を複製してローカルのmysqlデータベースにインポートしました。Django TypeError:allow_migrate()は予期しないキーワード引数 'model_name'を持っています

しかし、私はmakemigrationsを実行しようとすると、それは私にはTypeErrorを与える:allow_migrate()は、予期しないキーワード引数「MODEL_NAME」を得た

これは、完全なスタックトレースです:

Traceback (most recent call last): 
    File "manage.py", line 10, in <module> 
execute_from_command_line(sys.argv) 
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line 
utility.execute() 
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute 
self.fetch_command(subcommand).run_from_argv(self.argv) 
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/management/base.py", line 305, in run_from_argv 
self.execute(*args, **cmd_options) 
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/management/base.py", line 353, in execute 
self.check() 
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/management/base.py", line 385, in check 
include_deployment_checks=include_deployment_checks, 
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/management/base.py", line 372, in _run_checks 
return checks.run_checks(**kwargs) 
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks 
new_errors = check(app_configs=app_configs) 
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/checks/model_checks.py", line 30, in check_all_models 
errors.extend(model.check(**kwargs)) 
File "/home/cicd/.local/lib/python2.7/site-packages/django/db/models/base.py", line 1266, in check 
errors.extend(cls._check_fields(**kwargs)) 
File "/home/cicd/.local/lib/python2.7/site-packages/django/db/models/base.py", line 1337, in _check_fields 
errors.extend(field.check(**kwargs)) 
File "/home/cicd/.local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 893, in check 
errors = super(AutoField, self).check(**kwargs) 
File "/home/cicd/.local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 208, in check 
errors.extend(self._check_backend_specific_checks(**kwargs)) 
File "/home/cicd/.local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 310, in _check_backend_specific_checks 
if router.allow_migrate(db, app_label, model_name=self.model._meta.model_name): 
File "/home/cicd/.local/lib/python2.7/site-packages/django/db/utils.py", line 300, in allow_migrate 
allow = method(db, app_label, **hints) 
TypeError: allow_migrate() got an unexpected keyword argument 'model_name' 

私はいずれかをいただければ幸いですこのエラーのデバッグに役立ち、このエラーの原因を理解しようとしています。

+0

これに関連するかもしれません:https://docs.djangoproject.com/en/1.9/releases/1.8/#signature-of-the-allow-migrate-router-method。 Djangoのどのバージョンを新しいサーバーで使用していますか? – elethan

+0

確かに私は1.9.4から1.10に移行しましたが、あなたがリンクしたこの機能の変更が1.8から1.9になっているので、これが原因です。 –

+0

1.9.4にダウングレードして、問題を修正しました。しかし、私はまだなぜ疑問に思っていますか? –

答えて

5

私は1.6から移動したときに、私は同じ問題を満たしています。* 1.10.Finallyに私はDATABASE_ROUTERS

で私はこの

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 

それが仕事のよう書く古いバージョンを、問題の原因を発見しました書き換えによって

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 

このような詳細は https://docs.djangoproject.com/en/1.10/topics/db/multi-db/#an-example

を見ます
関連する問題