ERROR COLLECTION
[ERROR] 'id' can only be used as a field name if the field also sets 'primary_key=True'
adore_voy
2020. 11. 6. 15:08
상황
- 로그인 아이디와 비밀번호를 입력하려고, 필요한 장고 모델을 생성하려고 함.
때문에, 'id'와 'password'라는 이름의 데이터베이스를 만들기로 했다.
그리고 마이그레이션을 하려고 하는 중,
이러한 에러 발생
찾은방법들
groups.google.com/g/django-users/c/h4s36KNOt9M?pli=1
inspectDB and 'id' can only be used as a field name if the field also sets 'primary_key=True'.
G'day, Very new to Django, I'm trying to connect to an existing MySQL database that I am not familiar with. I used inspectDB to load up the database models.py file, and am seeing these errors for some of the tables : 'id' can only be used as a field name
groups.google.com
해결방법
id는 이미 장고모델이 제공하는 키였다. 때문에, 이름을 수정해야함.
그렇기에 id는 trinity_id로, password는 trinity_password로 수정했다.
이렇게 이미 있는 명령어나 문법이 아닐지 헷갈리거나 의심되는 경우에 사용하고자 하는 변수명 앞에 _를 붙이는 방법이 있다고 한다.
성공.
반응형