2017-10-02 30 views
0

私はHerokuのRailsアプリケーションの新しい移行を作成しました。それはこのようにいくつかの配列の列を追加します。Rails Postgreの問題:不正な配列リテラル、配列値が "{"またはディメンション情報で始まる必要があります

t.string :timezone, array: true, default: [].to_yaml 
t.string :locale, array: true, default: [].to_yaml 

私が移行しようとすると、私は次のエラーを取得する:StackOverflowの上

class Filter < ApplicationRecord 
    belongs_to :letter 
    serialize :timezone 
    serialize :locale 
    serialize :segment 
    validates_uniqueness_of :letter_id 
end 

一部の人々は言う:ここ

ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR: malformed array literal: "--- [] " DETAIL: Array value must start with "{" or dimension information. : CREATE TABLE "filters" ("id" serial primary key, "letter_id" integer, "gender" character varying, "timezone" character varying[] DEFAULT '--- [] ', "locale" character varying[] DEFAULT '--- []

は私のモデルであり、シリアライズを削除するとそのトリックが実行されますが、文字列ではなく配列を格納する必要があります。

どうすればこの問題を解決できますか?

答えて

0

は、なぜあなたはちょうど行いません。

t.text :your_table, :timezone, default: [] 
t.text :your_table, :locale, default: [] 

わからない、なぜあなたはデフォルト値のためto_yamlを呼び出します。また、文字列textを使用する必要があります。文字列はデフォルトで255文字に制限される可能性があるからです。最後に

0

は、私は次のことをやったし、それは私の問題を解決:

t.string :timezone, :string 
t.string :locale, :string 

そして、シリアル化と私のモデルを保ちました。

関連する問題