๐Ÿ™Œ๐Ÿป Django ๋ชจ๋ธ ํ•„๋“œ ์ •์˜ํ•˜๊ธฐ

may_soouuยท2021๋…„ 1์›” 11์ผ
0
post-thumbnail

django์—์„œ ๋ชจ๋ธ ํ•„๋“œ๋ฅผ ์ •์˜ํ• ๋•Œ null = True ์™€ blank=True ์˜ ์˜ต์…˜ (๊ธฐ๋ณธ๊ฐ’์€ ๋‘˜ ๋‹ค false๋กœ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค) ๋“ฑ ์ผ๋ฐ˜์ ์ธ ๊ฐ€์ด๋“œ๋ฅผ ์ •๋ฆฌํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

ํ•„๋“œ ํƒ€์ž…null=True ์„ค์ •ํ•˜๊ธฐblank = True ์„ค์ •ํ•˜๊ธฐ
CharField, TextField, SlugField, EmailField, CommaSeparatedIntegerField, UUIDField์ด์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์žฅ๊ณ  ํ‘œ์ค€์€ ๋„ ๊ฐ’ ๋˜๋Š” ๋นˆ ๊ฐ’์„ ๋นˆ ๋ฌธ์ž์—ด๋กœ ์ €์žฅํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.์ด์šฉํ•ฉ๋‹ˆ๋‹ค. ์œ„์ ฏ์ด ๋นˆ ๊ฐ’์„ ํ—ˆ์šฉํ•˜๊ธฐ๋ฅผ ์›ํ•œ๋‹ค๋ฉด ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์œ„์™€ ๊ฐ™์ด ์„ค์ •ํ•˜๋ฉด DB์—์„œ๋Š” ๋นˆ ๊ฐ’์ด ๋นˆ ๋ฌธ์ž์—ด๋กœ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.
FileField, ImageField์ด์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. CharField์™€ ๊ฐ™์€ ํŒจํ„ด์ž…๋‹ˆ๋‹ค.์ด์šฉํ•ฉ๋‹ˆ๋‹ค. CharField์™€ ๊ฐ™์€ ํŒจํ„ด์ž…๋‹ˆ๋‹ค.
BooleanField์ด์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋Œ€์‹  NullBooleanField๋ฅผ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.์ด์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
IntegerField, FloatField, DecimalField, DurationFieldDB์—์„œ ํ•ด๋‹น ๊ฐ’๋“ค์„ Null๋กœ ์„ค์ •ํ•˜๋Š” ๊ฒŒ ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.null = True๋ฅผ ์ด์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.
DateTimeField, DateField, TimeFieldDB์—์„œ ํ•ด๋‹น ๊ฐ’๋“ค์„ Null๋กœ ์„ค์ •ํ•˜๋Š” ๊ฒŒ ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.null = True๋ฅผ ์ด์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.
ForeignKey, ManyToManyField, OneToOneFieldDB์—์„œ ํ•ด๋‹น ๊ฐ’๋“ค์„ Null๋กœ ์„ค์ •ํ•˜๋Š” ๊ฒŒ ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.์œ„์ ฏ์—์„œ ํ•ด๋‹น ๊ฐ’๋“ค์„ ๋นˆ ๊ฐ’์œผ๋กœ ์„ค์ •ํ•˜๋Š” ๊ฒŒ ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.
GenericIPAddressFieldDB์—์„œ ํ•ด๋‹น ๊ฐ’๋“ค์„ Null๋กœ ์„ค์ •ํ•˜๋Š” ๊ฒŒ ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.์œ„์ ฏ์—์„œ ํ•ด๋‹น ๊ฐ’๋“ค์„ ๋นˆ ๊ฐ’์œผ๋กœ ์„ค์ •ํ•˜๋Š” ๊ฒŒ ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.

์ถœ์ฒ˜ : Two Soops of Django

profile
back-end ๊ฐœ๋ฐœ์ž

0๊ฐœ์˜ ๋Œ“๊ธ€