django - 在 Heroku 和 Django 应用程序上添加迁移的问题
问题描述
我在 Heroku 上遇到了迁移问题。我在本地做了一些模型更改,在本地也顺利迁移了它——没问题。当我在 Heroku 上重新部署我的应用程序(应用程序已经存在旧的迁移前数据库)并运行迁移时,我得到以下输出:
python manage.py makemigrations on ⬢ boatsproject-eu... up, run.2252 (Free)
Migrations for 'articles':
articles/migrations/0018_auto_20190613_1240.py
- Add field change_date to comment
- Add field change_date to heading
- Alter field change_date on article
- Alter field title on article
- Alter field author on comment
Migrations for 'boats':
boats/migrations/0028_auto_20190613_1240.py
- Add field change_date to boatimage
- Add field change_date to boatmodel
- Alter field boat_name on boatmodel
这些是要应用的新更改
最后迁移:
heroku run -a boatsproject-eu python manage.py migrate
Running python manage.py migrate on ⬢ boatsproject-eu... up, run.7674 (Free)
Operations to perform:
Apply all migrations: admin, articles, auth, boats, captcha, contenttypes, easy_thumbnails, reversion, sessions, social_django, testapp
Running migrations:
Applying articles.0017_auto_20190517_1713... OK
Applying boats.0026_auto_20190522_1053... OK
Applying boats.0027_auto_20190530_1536... OK
Applying reversion.0001_squashed_0004_auto_20160611_1202... OK
Applying social_django.0001_initial... OK
Applying social_django.0002_add_related_name... OK
Applying social_django.0003_alter_email_max_length... OK
Applying social_django.0004_auto_20160423_0400... OK
Applying social_django.0005_auto_20160727_2333... OK
Applying social_django.0006_partial...Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
psycopg2.errors.DuplicateTable: relation "social_auth_partial" already exists
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 234, in handle
fake_initial=fake_initial,
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/migrations/operations/models.py", line 92, in database_forwards
schema_editor.create_model(model)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 307, in create_model
self.execute(sql, params or None)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 137, in execute
cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "social_auth_partial" already exists
它在本地,我可以手动删除迁移文件并从头开始迁移或删除最后一次迁移,但是在 Heroku 上该怎么做——我不知道。
想到的只有一件事是将带有空迁移文件夹的代码移动到 GitHub 并从那里部署并从初始迁移运行迁移,但这似乎有点矫枉过正。
你会建议我采取一些措施来应对这种情况吗?
谢谢
PS我已经阅读了这篇Django 1.7 - “No migrations to apply” when run migrate after makemigrations ,尝试了一些 - 没有成功,似乎我什至深埋了我的回归之路
移民
python manage.py showmigrations on ⬢ boatsproject-eu... up, run.1339 (Free)
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
[X] 0003_logentry_add_action_flag_choices
articles
[X] 0001_squashed_0015_auto_20190513_1722 (15 squashed migrations)
[X] 0016_auto_20190513_1808
[X] 0017_auto_20190517_1713
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
boats
[X] 0001_squashed_0025_auto_20190507_2237 (25 squashed migrations)
[X] 0026_auto_20190522_1053
[X] 0027_auto_20190530_1536
captcha
[X] 0001_initial
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
easy_thumbnails
[X] 0001_initial
[X] 0002_thumbnaildimensions
reversion
[X] 0001_squashed_0004_auto_20160611_1202
sessions
[X] 0001_initial
social_django
[X] 0001_initial (2 squashed migrations)
[X] 0002_add_related_name (2 squashed migrations)
[X] 0003_alter_email_max_length (2 squashed migrations)
[X] 0004_auto_20160423_0400 (2 squashed migrations)
[X] 0005_auto_20160727_2333 (1 squashed migrations)
[ ] 0006_partial
[ ] 0007_code_timestamp
[ ] 0008_partial_timestamp
testapp
[X] 0001_initial
PS C:\Users\hardcase1\PycharmProjects\myproject>
解决方案
推荐阅读
- masstransit - 如果消息无法完成,则停止消费
- gradle - 如何修复 gradle 错误:“不再支持源选项 5。使用 6 或更高版本”?
- python - 有没有办法使用 Github Actions 停止和重新启动自托管 Python 脚本?
- r - 有没有办法改变像 paste 这样的函数中的参数顺序,这些函数按顺序排列向量,使其与管道运算符兼容?
- angular - 如何在 Angular 10 中使用 ngforage
- firebase - 长列表的 Flutter 应用程序性能问题
- quarkus - 使用 Quarkus 运行 Specs2
- video - 如何仅在不兼容的浏览器中播放 MP4 HEVC (h265) 视频文件时检测音频?
- python - 安装扩展 plotly jupyter lab 后出现 PermissionError
- c# - AutoCAD 2021 .NET API:获取数据库中的所有块引用?