简体   繁体   English

模型包含 created_at 和 updated_at 日期时间字段时的 django 操作错误

[英]django operational error when model contains created_at and updated_at datetime fields

models.py模型.py

class Profile(models.Model):
    user = models.OneToOneField(User,on_delete=models.CASCADE)
    # on_deleting user, profile will also be deleted
    image = models.ImageField(default="profilepic.jpg",upload_to="profile_pictures")
    dob = models.DateField(null=True)
    bio = models.TextField(null=True)
    anonymous = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    def __str__(self):
        return f'{self.user.username} Profile'

my model has been working just fine untill now.到目前为止,我的模型一直运行良好。 I recently added created_at and updated_at fields to the form.我最近在表单中添加了 created_at 和 updated_at 字段。 I deleted all the files in migration folder.我删除了迁移文件夹中的所有文件。 did makemigrations and migrate to start fresh.做了迁移并迁移以重新开始。

despite all this, i keep getting the error : no such column: users_profile.created_at尽管如此,我仍然收到错误消息:没有这样的列:users_profile.created_at

You've made changes on your model but you need to add "created_at" and "updated_at" to your schema fields.您已经对模型进行了更改,但您需要将“created_at”和“updated_at”添加到您的架构字段中。

Example:例子:

userSchema = create_schema(Profile, fields=['user', 'image', 'dob', 'bio', 'anonymous', 'created_at', 'updated_at'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM