Schema.rb display Could not dump table “progresses

2019-09-15 15:12发布


I am trying to add a multiple image uploader with Carrierwave following the documentation to my app.

Normally my schema.rb looks like this

  ActiveRecord::Schema.define(version: 20160814232416) do

   create_table "progresses", force: :cascade do |t|
     t.string   "title"
     t.string   "date"
     t.text     "content"
     t.datetime "created_at", null: false
     t.datetime "updated_at", null: false
    end
  end

And when I run :

rails g migration add_images_to_progresses images:json and rake db:migrate

My schema change and display that weird thing.... Is it a problem with Sqlite3 or Pg? What should I do ?

ActiveRecord::Schema.define(version: 20160815005123) do

  # Could not dump table "progresses" because of following NoMethodError
  #undefined method `[]' for nil:NilClass

end

1条回答
【Aperson】
2楼-- · 2019-09-15 16:07

I tried using the same code for both SQLite and PostgreSql. In SQLite there is no datatype "JSON" available, and so it throws an error. When I tried the same in PostgreSQL, it worked.

ActiveRecord::Schema.define(version: 20160815070637) do 
  enable_extension "plpgsql"
  create_table "progresses", force: :cascade do |t|
    t.string   "title"
    t.string   "date"
    t.text     "content"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.json     "images"
  end

end

If you want to use the SQLite then you will have to generate a string from your JSON and then save that string in your database as a regular string.

I prefer to use PostgreSQL, which supports JSON datatype.

查看更多
登录 后发表回答