【问题标题】:Django migrations fail in herokuDjango 迁移在 Heroku 中失败
【发布时间】:2015-06-26 06:21:44
【问题描述】:

我正在尝试将 Django (1.8) 应用程序部署到 Heroku,运行时 Python 3.4.2。该应用程序成功运行(除了未创建表的事实),但在尝试运行 syncdb 时出现以下错误:

Running `python manage.py syncdb` attached to terminal... up, run.5851
/app/.heroku/python/lib/python3.4/site-packages/django/core/management       
/commands/syncdb.py:24: RemovedInDjango19Warning: The syncdb command 
will be removed in Django 1.9
warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)

Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/loader.py", line 157, in check_key
return list(self.graph.root_nodes(key[0]))[0]
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.4/site-packages/django /core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/commands/syncdb.py", line 25, in handle
call_command("migrate", **options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 93, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/executor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/loader.py", line 287, in build_graph
parent = self.check_key(parent, key[0])
File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/loader.py", line 164, in check_key
raise ValueError("Dependency on app with no migrations: %s" % key[0])
ValueError: Dependency on app with no migrations: authentication

我正在使用 sqlite。

【问题讨论】:

  • 您安装的应用中有authentication吗?
  • 是的,身份验证在已安装的应用程序中。

标签: django heroku django-migrations


【解决方案1】:

在您的开发机器上,使用python manage.py makemigrations 创建您的迁移。然后,假设您的迁移文件夹被推送到heroku,在heroku 上运行python manage.py migrate 而不是python manage.py syncdb。请参阅docs

【讨论】:

  • 我也有同样的问题。我该如何处理我的 virtualenv 中的 django 应用程序的迁移?也许这不是我的问题,我不确定。
  • 尝试 heroku run python manage.py migrate。这将迁移生产机器的 virtualenv 中的应用程序。
【解决方案2】:

我不得不进入heroku的机器bash

heroku run bash

然后制作makemigrations:

heroku run python manage.py makemigrations

最后,

heroku run python manage.py migrate

【讨论】:

    【解决方案3】:

    对我来说,我通过使用我们在本地服务器中使用的带有前缀“heroku run”的相同命令解决了这个问题..

    例如:-

    python manage.py makemigrations 
    

    它可以在我们的本地工作,但对于 heroku,像这样:-

    heroku run python manage.py makemigrations
    

    【讨论】:

      猜你喜欢
      • 2015-01-13
      • 1970-01-01
      • 2021-05-17
      • 2011-06-29
      • 2020-05-29
      • 2011-08-05
      • 1970-01-01
      • 2017-03-10
      相关资源
      最近更新 更多