将django 1.6升级到1.7。 " related_name"?的通用关系是否有任何变化?

时间:2015-03-02 12:34:21

标签: python django upgrade

我正在尝试将项目从Django 1.6升级到1.7。当我尝试运行服务器时,我得到“TypeError: init ()得到一个意外的关键字参数'related_name'”:

$ ./manage.py runserver --settings=bertondealer.settings.local 0.0.0.0:8000

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/apps/config.py", line 197, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/vagrant_data/projects/companyapps/clientes/models.py", line 3, in <module>
    from distribuidores.models import Empresa as Distribuidor
  File "/vagrant_data/projects/companyapps/distribuidores/models.py", line 50, in <module>
    class Empresa(models.Model):
  File "/vagrant_data/projects/companyapps/distribuidores/models.py", line 88, in Empresa
    eventos = generic.GenericRelation(Evento, related_name='distribuidores_set')
  File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/contrib/contenttypes/fields.py", line 266, in __init__
    from_fields=[self.object_id_field_name], **kwargs)
  File "/home/vagrant/.virtualenvs/dealer17/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1309, in __init__
    super(ForeignObject, self).__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'related_name'

这与Django 1.7的任何变化有关吗?

1 个答案:

答案 0 :(得分:2)

GenericKey没有related_name

但您可以在django 1.7中使用related_query_name代替related_name