models.py
### 위치 이동
cd /Users/user/test/django/project/web/bookmark
### models.py 수정
vi models.py
---
#from django.db import models
# Create your models here.
from __future__ import unicode_literals
from django.db import models
class Bookmark(models.Model):
title = models.CharField(max_length=100, blank=True, null=True)
url = models.URLField('url', unique=True)
def __str__(self):
return self.title
models.py
models.py 에서 정의한 테이블을 admin 사이트에서 확인할 수 있도록 admin.py 에 등록
### 위치 이동
cd /Users/user/test/django/project/web/bookmark
### adminn.py 수정
vi admin.py
---
# from django.contrib import admin
# Register your models here.
from django.contrib import admin
from bookmark.models import Bookmark
class BookmarkAdmin(admin.ModelAdmin):
list_display = ('title', 'url')
admin.site.register(Bookmark, BookmarkAdmin)
테이블의 신규 생성, 정의 변경 등의 수정이 필요한 경우, 실제로 반영해주는 작업
### 위치 이동
cd /Users/user/test/django/project/web
### makemigrations
python3 manage.py makemigrations

ls /bookmark/migrations

### migrate
python3 manage.py migrate

해당 명령어는 django 모델에 대한 변경 사항을 감지하고, 이러한 변경 사항을 감지하고, 변경 사항을 설명하는 마이그레이션 파일을 생성하며, 마이그레이션 파일은 데이터베이스 스키마 변경 사항을 기록한 일종의 히스토리 파일
migrate 명령어는 makemigrations 명령어로 생성된 마이그레이션 파일을 실제 데이터베이스에 적용하며, 데이터베이스 스키마를 변경하여 모델 변경 사항을 반영
### 위치 이동
cd /Users/user/test/django/project/web/web
### settings.py 수정
vi settings.py
---
### 수정 전
ALLOWED_HOSTS = []
### 수정 후
ALLOWED_HOSTS = ['*']
### 위치 이동
cd /Users/user/test/django/project/web
### django 구동
python3 manage.py runserver 0.0.0.0:8000


애플리케이션 이름

객체명

참고 자료