swsnu / swppfall2019

31 stars 23 forks source link

[Project] travis mysql migration error #215

Open ByungHeeCha opened 4 years ago

ByungHeeCha commented 4 years ago

저희는 혹시 모를 상황을 대비해 .travis.yml에

- python manage.py makemigrations
- python manage.py migrate

을 넣어두었습니다.

그런데 mysql 로 바꾸고 나서 부터 travis에서 build할때 django.db.utils.OperationalError: (1060, "Duplicate column name 'num_of_review’”) migrate할때 이런 에러가 자꾸 뜨더라구요. 또, test 할때 Got an error creating the test database: (1007, "Can't create database 'test_team10_db_jaeho'; database exists") 이런 에러가 자꾸 뜹니다.

스택오버플로우에 물어봐도 시원한 대답이 없는것 같아서 질문드렸습니다. 어떻게 해결할 방법이 없을까요?

kyunggeunlee commented 4 years ago

테스트를 할 때 python manage.py makemigrationspython manage.py migrate 를 실행하실 필요는 없을 것 같습니다. 저 둘을 실행하지 않고 travis build / test를 해도 똑같은 결과가 나오시나요?

ByungHeeCha commented 4 years ago

Got an error creating the test database: (1007, "Can't create database 'test_team10_db_jaeho'; database exists") 이 에러가 나옵니다.

ByungHeeCha commented 4 years ago

그거는 어떻게 해결했는데 이제 django.db.utils.ProgrammingError: (1146, "Table 'test_team10_db_jaeho.foodbook_api_restaurant' doesn't exist") 에러가 나오네요

kyunggeunlee commented 4 years ago

제 생각엔 migration을 하면서 뭔가가 꼬인 것 같습니다. 현재 DB에 dummy data 이외에 중요한 내용은 없을테니, python manage.py flush 한 뒤에 다시 migration을 해보는 것이 가장 쉬운 방법일 것 같습니다. 만약 많은 양의 dummy data를 공들여 만들어놔서 그것들이 날아가지 않게 하려면 아래 링크를 참고해서 조치해보시면 어떨까 합니다. https://stackoverflow.com/questions/27583744/django-table-doesnt-exist

ulgal commented 4 years ago

혹시 안되시면 이 방법대로 해보시는건 어떨까요? travis에 mysql이 깔려있어서

- language: python
      sudo: enabled
      services:
        - mysql
      addons:
        apt:
          sources:
            - mysql-5.7-trusty
          packages:
            - mysql-server
...
      before_install:
        - mysql -e "CREATE DATABASE (Your Database Name);"
        - mysql -e "CREATE USER '(Your User Name)'@'localhost' IDENTIFIED BY '(Your User Password)';"
        - mysql -e "GRANT ALL PRIVILEGES ON *.* to '(Your User Name)'@'localhost';"
      install:
...

처럼 해주면 저희 조는 잘 됐습니다. 처음 로컬에서 mysql 설정할 때처럼 Table을 만들어주고 settings.py에 있는 정보대로 유저이름과 비밀번호를 만들어 준 뒤 권한을 줍니다. mysql test 방식이 test table을 만들어서 테스트하고 drop하는 것 같아서 모든 권한을 줘야 동작하는 것 같더라구요.