如何解决“对于类型字符变化(255)而言太长的值"?错误 [英] How to fix a "value too long for type character varying(255)" error

查看:217
本文介绍了如何解决“对于类型字符变化(255)而言太长的值"?错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保存文件,以便可以使用CarrierWave将其上传到条带中,但出现错误:

I'm trying to save a file so that I can upload it to stripe using CarrierWave, but I'm getting the error:

ERROR: value too long for type character varying(255)

并且不明白为什么要遵循GitHub上的CarrierWave使用指南.

and don't understand why as I followed the CarrierWave usage guide on GitHub.

这是我的应用程序

class SplitterStripeServer < Sinatra::Base

  CarrierWave.configure do |config|
    config.root = File.dirname(__FILE__) + "/public"
  end

  post "/" do
    img = Image.new
    img.file = params[:file] #carrierwave will upload the file automatically
    img.save!
    redirect to("/")
  end

  get "/upload" do
    erb :upload
  end

  get "/" do
    @image = Image.find(1)
    erb :index
  end
end

这是上传者:

class ImagesUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick
  storage :file
end

这是模型:

class Image
  include DataMapper::Resource

  property :id, Serial

  mount_uploader :file, ImagesUploader
end

我觉得我缺少一些简单的东西.

I feel like I'm missing something simple.

推荐答案

检查是否还安装了其他gems我已经安装了gem validates_lengths_from_database ,而这个gem不了解如何使用载波.我只是在模型 validates_lengths_from_database中将其关闭,除了:%i [file]

check if you have additional installed gems I had was installed gem validates_lengths_from_database and this gem doesn't understand how to work with carrierwave. I am just turn off it in model validates_lengths_from_database except: %i[file]

这篇关于如何解决“对于类型字符变化(255)而言太长的值"?错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆