Django创建模型,迁移数据

1.在models.py文件中添加代码

class notice(models.Model):
    notice_title = models.CharField(max_length=255)
    notice_content = models.TextField()
    notice_user = models.CharField(max_length=20)
    notice_user_id = models.IntegerField(max_length=11)
    notice_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.notice_title

2.执行python manage.py makemigrations RRMS

3.查看迁移将运行的SQL:python manage.py sqlmigrate RRMS 0001

4.迁移数据,数据库中创建这些模型表:python manage.py migrate

猜你喜欢

转载自www.cnblogs.com/ttzz/p/10245667.html