我在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并从那里进行部署,并从初始迁移中进行迁移,但这似乎有些过分。
您会建议我针对这种情况采取一些措施吗?
谢谢
P.S。我已经读过这个Django 1.7 - "No migrations to apply" when run migrate after makemigrations,尝试了一些–没有成功,似乎我甚至为此深埋了自己的路
Shwomigrations
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>