2016-04-11 11 views
3

Ectoの移行で自分のテーブルを参照する外部キーを実装する正しい方法は何ですか?エリクサーエクト:自己参照外部キーを作成するにはどうすればよいですか?

私は任意の行が同じテーブル内の "親"行を参照するテーブルを作成したいと思います。 (階層データを行うための1つの方法、他の多くの方法があります。)

しかし、私は私のチェンジセットでこれを持っているときmix ecto.migrateを実行しているとき、私はエラーの多くを得る:

create_if_not_exists table(:perms, prefix: :accts) do 
    add :title, :string, size: 64, null: false 
    add :description, :text 
    add :parent_id, :integer, references(:perms) 
end 

エラーメッセージが(UndefinedFunctionError) undefined function Ecto.Migration.Reference.fetch/2 (Ecto.Migration.Reference does not implement the Access behaviour)で始まりますGenServerが終了する前に(これは外部1.1.5と2.0.0-beta2の下で発生します)

答えて

4

答えは単純な間違いです。外部キー列の列の種類を指定しようとするとエラーが発生します。正しい構文は次のとおりです(不足しているのは:integerアトムです)。

create_if_not_exists table(:perms, prefix: :accts) do 
    add :title, :string, size: 64, null: false 
    add :description, :text 
    add :parent_id, references(:perms) 
end 
関連する問題