PostgreSQL Auto Increment Primary key 추가하는 방법 PGAdmin

나의 재물운? 연애운은?

AI가 봐주는 내 사주팔자 - 운세박사

https://aifortunedoctor.com/

PostgreSQL Auto Increment Primary key 추가하는 방법 PGAdmin

영리치 0 1,164 2023.01.27 15:37

990564053_hlMpJxNk_0fe8dc9a6a8fe6a0d9e385bbbb3e581ad8e098f0.png


위와 같이 BigSerial 포맷으로 추가하면 알아서 생김


추가적인 것은 아래 링크 참고

https://stackoverflow.com/questions/48446399/sql-auto-increment-pgadmin-4



장고에서 Primary Key가 없는 데이터베이스에 외래키를 생성하려고 보니 해당 이슈가 발생됨


django.db.utils.ProgrammingError: there is no unique constraint matching given keys for referenced table "digital_relations"


위의 방법으로 DB에서 추가해준다



이미 존재하는 데이터베이스를 Django 모델로 만들고 그 모델에 내가 추가로 만든 모델에서 외래키로 등록하려고 할 때 원래 DB에 Primary Key가 없을 경우에는 PGAdmin에서 생성해줘야함. 아래와 같은 오류가 날 것이다.


django.db.utils.ProgrammingError: there is no unique constraint matching given keys for referenced table


990564053_FhglM3A7_5b3531efb63e34f13e02925dbdc4f34fe0fc49d1.png




그리고 특히나 다중 데이터베이스를 쓸 때에 Foreign key를 장고에서 지정해줄 때에는 아래 포스트를 보자

django foreign key different database


https://hangpark.com/django-multi-db-relation/


Comments

나의 재물운? 연애운은?

AI가 봐주는 내 사주팔자 - 운세박사

https://aifortunedoctor.com/

Category
실시간 인기글
난 아버지처럼 되지 않을래요
영리치
등록된 글이 없습니다.
Magazine
훈남/훈녀
 
 
 
상점
Facebook Twitter GooglePlus KakaoStory NaverBand