Skip to content

db 충돌 #9

@kmg22

Description

@kmg22

accounts_app.models.py User 클래스의 whishlist = ....ManyToManyField(products_app.Product,..)와
products_app.models.py Product 클래스 충돌 문제

에러코드 :
django.db.utils.OperationalError: (1829, "Cannot drop column 'id': needed in a foreign key constraint '회원목록_whishlist_product_id_94e5a63e_fk_products_app_product_id' of table '회원목록_whishlist'")

원인 추론 :
Product 테이블의 id형식이 수정된 부분이 뒤늦게 반영되어 whishlist 테이블과 충돌함

해결방법 :

  1. accounts_app과 products_app의 migrations 폴더 삭제
  2. python manage.py makemigrations products_app
  3. python manage.py migrate products_app
  4. python manage.py makemigrations accounts_app
  5. python manage.py migrate accounts_app

proudcts_app에 존재하는 Product테이블을 먼저 생성시킨 후
accounts_app migration 진행
.
.
.

(GreatJung 추가 내용)

  1. 우선 mysql에서 django랑 연동 되어있는 database 전체를 삭제 (DROP 명령어)
  2. 모든 app 디렉의 migrations 폴더안 0001 과 같은 migraion 내용 삭제
  3. python manage.py makemigrations
  4. python manage.py migrate

이렇게만 해도 가능함

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions