Why can't I create an array as a column in a table in Rails?

前端 未结 3 642
囚心锁ツ
囚心锁ツ 2021-01-05 19:23

Why can\'t I do something like this:

class CreateModels < ActiveRecord::Migration
  def self.up
    create_table :fruit do |t|
      t.array :apples
    e         


        
3条回答
  •  囚心锁ツ
    2021-01-05 19:49

    In Rails 4 and using PostgreSQL you can actually use an array type in the DB:

    Migration:

    class CreateSomething < ActiveRecord::Migration
      def change
        create_table :something do |t|
          t.string :some_array, array: true, default: []
          t.timestamps
        end
      end
    end
    

提交回复
热议问题