我正在使用Dokku将Django项目部署到VPS。我的项目使用CustomUser
模型,项目中有两个应用程序:accounts
,它有CustomUser和gradebook
。
在部署期间,流程运行、生成和迁移。在部署之后,当我运行python manage.py showmigrations
时,会得到以下内容:
account
[X] 0001_initial
[X] 0002_email_max_length
accounts
(no migrations)
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
[X] 0003_logentry_add_action_flag_choices
auth
[X] 0001_initial
[X] 0002_alter_permission_name_max_length
[X] 0003_alter_user_email_max_length
[X] 0004_alter_user_username_opts
[X] 0005_alter_user_last_login_null
[X] 0006_require_contenttypes_0002
[X] 0007_alter_validators_add_error_messages
[X] 0008_alter_user_username_max_length
[X] 0009_alter_user_last_name_max_length
[X] 0010_alter_group_name_max_length
[X] 0011_update_proxy_permissions
[X] 0012_alter_user_first_name_max_length
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
gradebook
(no migrations)
sessions
[X] 0001_initial
sites
[X] 0001_initial
[X] 0002_alter_domain_unique
account
来自django-allauth
。看来我的应用程序没有被迁移。于是我做了:
me@myserver:/home$ dokku run gradebook python manage.py makemigrations accounts
success
Migrations for 'accounts':
accounts/migrations/0001_initial.py
- Create model CustomUser
me@myserver:/home$
看起来东西已经准备好迁移了。然后运行迁移并获得一个错误django - ValueError: Dependency on app with no migrations: accounts
。
shmish@Henry:/home$ dokku run gradebook python manage.py migrate accounts
success
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.8/site-packages/django/db/migrations/loader.py", line 174, in check_key
return 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 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 92, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/app/.heroku/python/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/app/.heroku/python/lib/python3.8/site-packages/django/db/migrations/loader.py", line 53, in __init__
self.build_graph()
File "/app/.heroku/python/lib/python3.8/site-packages/django/db/migrations/loader.py", line 235, in build_graph
self.add_external_dependencies(key, migration)
File "/app/.heroku/python/lib/python3.8/site-packages/django/db/migrations/loader.py", line 199, in add_external_dependencies
parent = self.check_key(parent, key[0])
File "/app/.heroku/python/lib/python3.8/site-packages/django/db/migrations/loader.py", line 181, in check_key
raise ValueError("Dependency on app with no migrations: %s" % key[0])
ValueError: Dependency on app with no migrations: accounts
2021/08/25 16:19:16 exit status 1
此时,我无法迁移我的任何一个应用程序。我发现另一件奇怪的事情是,我仍然能够createsuperuser
、进入shell、from accounts.models import CustomUser
并成功地查询CustomUser。
此错误看起来类似于以下内容:ValueError: Dependency on app with no migrations: account,但我没有看到解决方案。
Next我在开发服务器和prod服务器上重新创建了我的数据库。在dev上,我重新运行初始迁移,然后提交到我的存储库。然后,我部署到生产服务器上。迁移看起来很有效,但我无法通过登录和注册表单。我一直无法确定确切的错误是什么,但是页面超时了,并给出了一条信息:“我们很抱歉,但是出了问题。”我认为这是一条nginx信息。
经过几次尝试部署来解决这个问题后,我得到了新的迁移错误:
Your models in app(s): 'account' have changes that are not yet reflected in a migration, and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
这是一个无穷无尽的循环,似乎工作,然后迁移,然后错误回来。
注意-我能够进入shell并手动创建一个CustomUser
对象,但是我无法通过网站第一页上的表单。
现在看起来就像2015年的错误:Django Heroku Error "Your models have changes that are not yet reflected in a migration"
所有这些在我的开发环境中都很好,最大的区别是它是Docker,而prod是Dokku。
发布于 2021-08-25 16:38:27
检查git忽略、使文件夹迁移注释或从gitignore文件中删除
https://stackoverflow.com/questions/68926660
复制相似问题