A. custom 모델을 따로 만들어 줘야 한다.
보통 MySQL에서 auto increment primary key 설정할 때 unsigned로 하는데 장고는 integer를 쓰든, bigint를 쓰든 signed가 기본으로 설정된다. 왜 그렇게 하는지 이유는 모르겠다.
장고 기본 설정과 달리 unsigned로 하고 싶다면 custom 모델을 만드는 방법 밖에 없다.
아래 코드가 custom 모델 예이다.
위 모델을 불러다가 Book이란 모델을 만든다면 아래처럼 작성해야 한다. 이렇게 하면 auto increment되는 unsigned primary key를 만들 수 있다.
class Author(models.Model):
id = UnsignedAutoField(primary_key=True)
...
class Book(models.Model):
id = UnsignedAutoField(primary_key=True)
author = UnsignedForeignKey(Author, on_delete=models.SET_NULL)
...