昨天跟y总写完了用户登录系统,今天开始写自己课设管理系统的登录功能,建完表以后遇到,No module named 'app'
错误,又回看了视频,发现在迁移之前忘记注册了,在这再记录一下创建数据库的流程。
一:在models里写class(staff.py)
from django.db import models
from django.contrib.auth.models import User
class Staff(models.Model):
user = models.OneToOneField(User,on_delete=models.CASCADE)
photo = models.URLField(max_length=256,blank=True)
def __str__(self):
return str(self.user)
二:注册到管理员页面(admin.py)
from django.contrib import admin
from office_system.models.staff.staff import Staff
# Register your models here.
admin.site.register(Staff)
三:迁移
python3 manage.py makemigrations
python3 manage.py migrate
大功告成!