Rails 这是怎么回事啊?

tomwey · 2013年01月18日 · 最后由 knwang 回复于 2013年01月18日 · 2963 次阅读

在 Heroku 上部署应用,在 pg 数据库中用 text 类型字段保存了很大一段文字,但是仍然报错:

ActiveRecord::StatementInvalid (PG::Error: ERROR: value too long for type character varying(255)

这是怎么回事啊?求解答

migration 里写了 string 吧?

t.text :content

或者报的是另一个字段的错...

写的是 text 啊!并且我发现好像是保存带有 html 标签的字符串,就报这个错了。跟文字的长度没关系样,求指点啊!!!大神们

类型显然不是 text....

真的是这样写的啊 t.text :content

我发现往这个字段里面保存哪怕很少的带有 html 标签的字符串,都会报这个错

而且本地 sqlite 测试的时候就没有问题

看一下 schema.rb ?

create_table "law_details", :force => true do |t|
   t.string   "pub_date"
   t.string   "title"
   t.string   "doc_id"
   t.string   "summary"
   t.string   "exec_date"
   t.string   "pub_dept"
   t.string   "catalog"
   t.text     "content"
   t.integer  "version",         :default => 1
   t.boolean  "visible",         :default => true
   t.string   "action",          :default => "add", :null => false
   t.integer  "law_category_id"
   t.datetime "created_at",                         :null => false
   t.datetime "updated_at",                         :null => false
   t.string   "law_udid"
 end

 add_index "law_details", ["law_category_id"], :name => "index_law_details_on_law_category_id"
 add_index "law_details", ["title"], :name => "index_law_details_on_title"
 add_index "law_details", ["version"], :name => "index_law_details_on_version"

数据是保存到 content 字段的

检查一下 summary ?

summary 就存了几个文字啊,您的意思是也要改成 text 这种类型吗?

heroku run rake db:migrate

需要 登录 后方可回复, 如果你还没有账号请 注册新账号