반응형
모델 작업을 한 후에는 반드시 마이그레이션 작업을 해야한다는 것을 명심한다.
blog > models.py
from django.db import models
from django.urls import reverse
class Category(models.Model):
name = models.CharField(max_length=50, help_text='category')
def __str__(self):
return self.name
| 카테고리 생성 | |
| CharField | 문자열 필드 |
| max_length | 최대글자수 |
| help_text | 필드 도움말 |
makemigrations
python manage.py makemigrations
| makemigrations | 모델에서 탐지된 변경 사항을 기반으로 새 마이 그레이션을 생성 |
migrate
python manage.py migrate
| migrate | 데이터베이스 상태를 현재 모델 및 마이 그레이션 집합과 동기화 작업 |
blog 폴더 구조
blog/
__init__.py
admin.py
apps.py
migrations/
__init__.py
0001_initial.py
models.py
templates/
index.html
tests.py
urls.py
views.py반응형
'Python_WEB > Project-Kindergarten' 카테고리의 다른 글
| Project Code Review>Link to html File (0) | 2020.05.30 |
|---|---|
| Project Code Review>Creating Views (0) | 2020.05.30 |
| Project Code Review>Setting File Settings (0) | 2020.05.27 |
| Project Code Review>App Creation and Setup (0) | 2020.05.27 |
| Project Code Review>Development Server (0) | 2020.05.27 |