The reason that there are separate commands to make and apply migrations is because you'll commit migrations to your version control system and ship them with your app; they not only make your development easier, they're also usable by other developers and in production.
# project_name/urls.py
from django.urls import path
from django.contrib import admin
from app_name import views
urlpatterns = [path('app_name/', views.index), path('admin/', admin.site.urls)]
path(route, view, kwargs, name)
python manage.py migrate
# app_name/models.py
from django.db import models
class Table_name(models.Model):
# field_name = data_type(limitation)
string = models.CharField(max_length=200)
number = models.IntegerField(default=0)
date = models.DateField('Datetime')
class Table_name_2(models.Model):
table_1 = models.ForeignKey(Table_name, on_delete=models.CASCADE)
number = models.IntegerField(default=0)
# app_name/admin.py
from django.db import admin
from .models import Table_name
admin.site.register(Table_name)
# app_name/views.py
from django.http import HttpResponse
# 查看问题的详细信息
def detail(request, question_id):
return HttpResponse(f'you are looking for the detail of {question_id}')
# 查看投票结果
def results(request, question_id):
return HttpResponse(f'you are looking for the results of {question_id}')
# 实现投票
def vote(request, question_id):
return HttpResponse(f'you are voting on {question_id}')