어쩔 수 없이 참조관계를 바꾸게 됐다. Payment와 Matching이라는 테이블이 있는데 payment의 matching이라는 필드가 Matching 테이블을 참조한다.구독모델이 새로 생기는데 결제를 하면 횟수에 따라 matching이 n개 생겨야한다. 따라서 Matching 테이블이 Payment를 참조해야한다.
양쪽에서 참조관계를 만들거나 테이블 이름과 동일하게 필드 이름을 지정하면 circular dependency가 생기기 때문에 그렇게 하면 안된다.
payment_temp = models.IntegerField(null=True)
추가service.Payment.matching: (fields.E303) Reverse query name for 'service.Payment.matching' clashes with field name 'service.Matching.payment'.
HINT: Rename field 'service.Matching.payment', or add/change a related_name argument to the definition for field 'service.Payment.matching'.
django.db.utils.ProgrammingError: column "code" of relation "coupon_couponbatch" does not exist
이라는 에러가 났고 페이크로 migrate해서 해결. 보니까 실 디비를 건들지는 않고 migration file만 업데이트 된다. 이렇게 하고 내가 원하는 것만 진짜 migrate하니까 성공.django.db.utils.IntegrityError: insert or update on table "service_matching" violates foreign key constraint "service_matching_payment_temp_id_edbf67d3_fk_service_payment_id
코드베이스:
1. serviceapplication에서 payment 만들때 matching 필드 생성 로직 지우기(?)
2. serviceapplication에서 matching 필드 생성 후에 payment에 엮기
3. 새로운 구독모델 보고 로직 짜기
1. 실데이터 덤프 떠서 로컬과 실디비 싱크 맞추기
2. 데이터베이스 변경 해보기
3. migration 파일 지워서 initial만 --fake로 migrate했을 때 문제없는지 보기
4. 코드 베이스랑 합 맞춰봤을 때 잘 되는지 보기
5. 테스트 서버에 동일하게 적용해보기
6. 실서버에 적용
end result: migration file이 다 동일해야함
backup plan:
1. 브랜치 하나 파서 현재 형상 그대로 저장
2. 데이터베이스 덤프