Django迁移涉及外国依赖

时间:2018-03-29 08:55:43

标签: django jenkins django-migrations

我正在尝试处理"它可以在我的机器上运行"问题的类型。我有一个使用jenkins的django项目,它在迁移时失败了。使用此命令触发该步骤:python manage.py test -v 2 --noinput并返回追溯:

  Applying gloodny.0020_auto_20180314_1338... OK
  Applying openinghours.0001_initial... OK
  Applying payu_payment.0002_auto_20171222_1407... OK
  Applying sessions.0001_initial... OK
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
    super(Command, self).execute(*args, **options)
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 90, in handle
    failures = test_runner.run_tests(test_labels)
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/test/runner.py", line 532, in run_tests
    old_config = self.setup_databases()
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/test/runner.py", line 482, in setup_databases
    self.parallel, **kwargs
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/test/runner.py", line 726, in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 78, in create_test_db
    self.connection._test_serialized_contents = self.serialize_db_to_string()
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 122, in serialize_db_to_string
    serializers.serialize("json", get_objects(), indent=None, stream=out)
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/core/serializers/__init__.py", line 129, in serialize
    s.serialize(queryset, **options)
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/core/serializers/base.py", line 79, in serialize
    for count, obj in enumerate(queryset, start=1):
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 118, in get_objects
    for obj in queryset.iterator():
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/db/models/query.py", line 52, in __iter__
    results = compiler.execute_sql()
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 848, in execute_sql
    cursor.execute(sql, params)
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/var/lib/jenkins/workspace/papuportal/env/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "openinghours_company" does not exist
LINE 1: ...mpany"."slug", "openinghours_company"."logo" FROM "openingho...

这是由openinghours django library引起的。

我面临的问题更复杂,因为本地迁移运行没有错误:

  Applying gloodny.0020_auto_20180314_1338... OK
  Applying gloodny.0021_auto_20180320_1426... OK
  Applying gloodny.0022_auto_20180320_1550... OK
  Applying openinghours.0001_initial... OK
  Applying openinghours.0002_auto_20180320_1426... OK
  Applying payu_payment.0002_auto_20171222_1407... OK
  Applying sessions.0001_initial... OK
  Applying thumbnail.0001_initial... OK

我已将OPENINGHOURS_PREMISES_MODEL设置变量设置为我实际拥有的模型,我还尝试添加依赖项:

dependencies = [
         ('payu_payment', '0001_initial'),
         ('openinghours', '0002_auto_20180320_1426'),
     ] 

但是构建失败并出现此错误:

  

迁移payu_payment.0002_auto_20171222_1407依赖项引用不存在的父节点(u&#39; openinghours&#39;,u&#39; 0002_auto_20180320_1426&#39;)

如何修复这些迁移?

编辑我修复了评论中指出的拼写错误,但现在我可以在本地和jenkins上面用上面提到的命令运行测试我得到同样的错误。

0 个答案:

没有答案