【问题标题】:Django IntegerRangeField Error binding parameter probably unsupported typeDjango IntegerRangeField 错误绑定参数可能不支持类型
【发布时间】:2017-05-01 18:16:56
【问题描述】:

我正在尝试将 year_from 和 year_to 字段替换为模型中的 IntegerRangeField 字段,但在管理中添加新对象时出错。

问题是“错误绑定参数 4 - 可能是不受支持的类型。” 有人可以看一下并提供帮助吗?提前致谢!

models.py

from django.contrib.postgres.fields import IntegerRangeField
from django.core.validators import MinValueValidator, MaxValueValidator
from django.db import models


class Bancnote(models.Model):

    DOLLAR = 'Dollar'
    EURO = 'Euro'

    TYPE_CHOICES = (
        (DOLLAR , 'Dollar'),
        (EURO, 'Euro')
    )

    type = models.CharField(max_length=20, choices=TYPE_CHOICES, 
                            default=DOLLAR )
    par = models.PositiveIntegerField()
    year_from = models.PositiveIntegerField()
    year_to = models.PositiveIntegerField()
    year = IntegerRangeField()
    size = models.CharField(max_length=7)
    sign = models.CharField(max_length=20)
    desc = models.TextField(max_length=200)
    image = models.ImageField(upload_to='bons_images')

    def __str__(self):
        return str(self.par) + ' ' + self.type + ' ' + str(self.year_from) + 
                   '-' + str(self.year_to)

【问题讨论】:

    标签: python django python-3.x django-models


    【解决方案1】:

    看起来 IntegerRangeField 是 PostgreSQL 特定的表单字段 (IntegerRangeField)。如果您使用的是 PostgreSQL,请告诉我们。

    【讨论】:

    • 我的错,默认使用 sqlite3,现在在 postgresql 上工作正常。非常感谢!
    猜你喜欢
    • 2014-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多