Я столкнулся с проблемой миграции на 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 - «Нет применений миграций» при запуске миграции после 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>