【问题标题】:OperationalError at /admin/myforms/uploadedfile/add/ while adding data to Table using django admin使用 django admin 将数据添加到表时 /admin/myforms/uploadedfile/add/ 出现 OperationalError
【发布时间】:2021-05-29 00:42:00
【问题描述】:

我在使用 django admin 向表中添加数据时遇到问题,我显然是 django 概念的新手,我不知道自己犯了什么错误。

它在手动向表中添加数据时显示“/admin/myforms/uploadedfile/add/ 处的操作错误”。并说该表不存在。但是在迁移时,它会将表名显示为 uploadfiles 。我只想手动添加数据并将其保存在 django admin 中。

所以附上截图

我删除了 Migration 里面的所有迁移文件,并尝试按照OperationalError at /admin/products/product/add/ no such table: main.auth_user__old所示的方式执行

但是在我执行完所有操作后仍然出现同样的错误,并且我的迁移文件夹是空的。

这是我的models.py

class Uploadedfile(models.Model):
    def file_path(self, filename):
        return f'uploaded_files/{self.server}/{self.path.replace(":", "$", 1)}/{filename}'

    files_to_upload = models.FileField(
        upload_to=file_path,
        default=None,
        validators=[validate_file]
    )
    
    
    path = models.CharField(max_length=100)
    server = MultiSelectField(choices=server_list)

谁能帮我解决这个问题。

【问题讨论】:

    标签: django file-upload


    【解决方案1】:

    您可以尝试刷新数据库,希望对您有所帮助。 如果您在 db 中有重要数据,则可以转储数据。 python manage.py flush python manage.py makemigrations python manage.py migrate

    【讨论】:

    • 抱歉没听懂
    • 它仍然说 table is not thr
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-19
    • 2019-10-12
    • 2011-03-28
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多