본문 바로가기
공부 및 활동/heroku, django

Heroku에서 발생한 Error

by KChang 2021. 10. 4.

1. 업데이트 꼬였을 때 발생하는 error

$ python manage.py migrate
Traceback (most recent call last):
  File "D:\Computer_Science\School\GraduationWork\gdproject\manage.py", line 22, in <module>
    main()
  File "D:\Computer_Science\School\GraduationWork\gdproject\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "D:\Computer_Science\School\GraduationWork\gdvenv\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "D:\Computer_Science\School\GraduationWork\gdvenv\lib\site-packages\django\core\management\__init__.py", line 413, in execute        
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\Computer_Science\School\GraduationWork\gdvenv\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv      
    self.execute(*args, **cmd_options)
  File "D:\Computer_Science\School\GraduationWork\gdvenv\lib\site-packages\django\core\management\base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "D:\Computer_Science\School\GraduationWork\gdvenv\lib\site-packages\django\core\management\base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "D:\Computer_Science\School\GraduationWork\gdvenv\lib\site-packages\django\core\management\commands\migrate.py", line 95, in handle  
    executor.loader.check_consistent_history(connection)
  File "D:\Computer_Science\School\GraduationWork\gdvenv\lib\site-packages\django\db\migrations\loader.py", line 306, in check_consistent_history
    raise InconsistentMigrationHistory(
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency gdapp.0001_initial on database 'default'.
(gdvenv)

업데이트가 꼬였을 때 발생하는 오류이다.

python manage.py showmigrations를 통해 조회한다.

KChang@LAPTOP-H1595VAD MINGW64 /d/Computer_Science/School/GraduationWork/gdproject (testbranch2)
$ python manage.py showmigrations
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
authtoken
 [X] 0001_initial
 [X] 0002_auto_20160226_1747
 [X] 0003_tokenproxy
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
gdapp
 [ ] 0001_initial
 [ ] 0002_alter_user_options
 [ ] 0003_alter_user_options
 [ ] 0004_auto_20210530_1413
sessions
 [X] 0001_initial
sites
 [X] 0001_initial
 [X] 0002_alter_domain_unique
social_django
 [ ] 0001_initial (2 squashed migrations)
 [ ] 0002_add_related_name (2 squashed migrations)
 [ ] 0003_alter_email_max_length (2 squashed migrations)
 [ ] 0004_auto_20160423_0400 (2 squashed migrations)
 [ ] 0005_auto_20160727_2333 (1 squashed migrations)
 [ ] 0006_partial
 [ ] 0007_code_timestamp
 [ ] 0008_partial_timestamp
 [ ] 0009_auto_20191118_0520
 [ ] 0010_uid_db_index
(gdvenv)

꼬여있다.

이를 위해서는?

프로젝트의 db.sqlite3 파일을 지워서, migration history 전체를 날려버리면 된다.

날린 후, python manage.py showmigrations migration history를 보니,

KChang@LAPTOP-H1595VAD MINGW64 /d/Computer_Science/School/GraduationWork/gdproject (testbranch2)
$ python manage.py showmigrations
admin
 [ ] 0001_initial
 [ ] 0002_logentry_remove_auto_add
 [ ] 0003_logentry_add_action_flag_choices
auth
 [ ] 0001_initial
 [ ] 0002_alter_permission_name_max_length
 [ ] 0003_alter_user_email_max_length
 [ ] 0004_alter_user_username_opts
 [ ] 0005_alter_user_last_login_null
 [ ] 0006_require_contenttypes_0002
 [ ] 0007_alter_validators_add_error_messages
 [ ] 0008_alter_user_username_max_length
 [ ] 0009_alter_user_last_name_max_length
 [ ] 0010_alter_group_name_max_length
 [ ] 0011_update_proxy_permissions
 [ ] 0012_alter_user_first_name_max_length
authtoken
 [ ] 0001_initial
 [ ] 0002_auto_20160226_1747
 [ ] 0003_tokenproxy
contenttypes
 [ ] 0001_initial
 [ ] 0002_remove_content_type_name
gdapp
 [ ] 0001_initial
 [ ] 0002_alter_user_options
 [ ] 0003_alter_user_options
 [ ] 0004_auto_20210530_1413
sessions
 [ ] 0001_initial
sites
 [ ] 0001_initial
 [ ] 0002_alter_domain_unique
social_django
 [ ] 0001_initial (2 squashed migrations)
 [ ] 0002_add_related_name (2 squashed migrations)
 [ ] 0003_alter_email_max_length (2 squashed migrations)
 [ ] 0004_auto_20160423_0400 (2 squashed migrations)
 [ ] 0005_auto_20160727_2333 (1 squashed migrations)
 [ ] 0006_partial
 [ ] 0007_code_timestamp
 [ ] 0008_partial_timestamp
 [ ] 0009_auto_20191118_0520
 [ ] 0010_uid_db_index
(gdvenv)

정말 깔끔해졌다.

이후 python manage.py migrate 가 잘 실행된다.😎

 

 

2. python와 heroku에서 showmigrations확인

1) django

KChang@LAPTOP-H1595VAD MINGW64 /d/Computer_Science/School/GraduationWork/gdproject (master)
$ python manage.py showmigrations
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
authtoken
 [X] 0001_initial
 [X] 0002_auto_20160226_1747
 [X] 0003_tokenproxy
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
gdapp
 [X] 0001_initial
sessions
 [X] 0001_initial
sites
 [X] 0001_initial
 [X] 0002_alter_domain_unique
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)
 [X] 0006_partial
 [X] 0007_code_timestamp
 [X] 0008_partial_timestamp
 [X] 0009_auto_20191118_0520
 [X] 0010_uid_db_index
(gdvenv)

2) heroku

KChang@LAPTOP-H1595VAD MINGW64 /d/Computer_Science/School/GraduationWork/gdproject (master)
$ heroku run python manage.py showmigrations
 »   Warning: heroku update available from 7.53.0 to 7.59.0.
Running python manage.py showmigrations on ⬢ dongagd... up, run.8258 (Free)
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
authtoken
 [X] 0001_initial
 [X] 0002_auto_20160226_1747
 [X] 0003_tokenproxy
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
gdapp
 [X] 0001_initial
 [X] 0002_alter_user_options
 [X] 0003_alter_user_options
 [X] 0004_auto_20210530_1413
sessions
 [X] 0001_initial
sites
 [X] 0001_initial
 [X] 0002_alter_domain_unique
(gdvenv)

1), 2)를 비교하면 크게 social_django가 추가되지 않을 것을 볼 수 있다.

이럴 경우, git에서 문제가 있는지 migrate가 실행되었는지 알아봐야 한다.

 

sourcetree에서 확인한 결과

이와같이

병합 과정에 겹친 소스가 있어 git push heroku master가 되지 않았던 것이다.

위부분을 수정해주면 migrate한 후 migration을 확인할 시 1), 2)가 똑같은 결과로 출력될 것이다.

댓글