【问题标题】:mapping django models.ImageField into an SQL table将 django models.ImageField 映射到 SQL 表中
【发布时间】:2012-09-26 08:02:42
【问题描述】:

我的模型中有一个图像,我想自己编写 SQL 创建表查询 我提交的模型是这样的:

pic = models.ImageField(u"initial_picture",blank=True,upload_to="/face")

我想使用命令CREATE TABLE SOME_TABLE_NAME 来创建我的表 但我不知道字段类型应该使用什么 我读过here 我可以使用这样的东西:

Photo varbinary(max) not null

但我不知道它是否与 django 兼容以及是否适合我的模型 我也使用了pic IMAGE DEFAULT NULL,就像我看到的here 一样,结果是数据库结构中的一个varchar(100) 字段

任何帮助都将得到应用 ;-)

Photo varbinary(max) not nullPhoto varchar(max) not null 我都试过了 该字段正在显示,但是当我按保存时,我收到以下错误:

Attempted access to '\face\sample.gif' denied.

【问题讨论】:

    标签: sql django django-models sql-types


    【解决方案1】:

    为什么不将图像作为普通文件保存在文件系统中?这将是相应的 SQL

    `pic` varchar(100) NOT NULL,
    

    为您的图片字段。

    pic = models.ImageField(u"initial_picture",blank=True,upload_to="/face")
    

    在数据库中,pic 字段将只包含实际图像文件的路径。

    【讨论】:

    • Django 的 ImageField,将实际的二进制文件保存在文件系统上。我不知道 OP 想要做什么。
    • 我也找到了错误Attempted access to '\face\sample.gif' denied.的答案,答案在这个页面中:stackoverflow.com/questions/7869549/…
    猜你喜欢
    • 2010-11-12
    • 1970-01-01
    • 2012-06-20
    • 2010-11-23
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 2018-10-22
    相关资源
    最近更新 更多