2016-08-09 8 views
1

'inserted_at' 不明な列エリクサー+フェニックスを使用してMySQLデータベースにモデルを挿入する際、私が得る:フェニックスエクト**(Mariaex.Error)(1054): 'フィールドリスト' で

** (Mariaex.Error) (1054): Unknown column 'inserted_at' in 'field list' 
    stacktrace: 
     (ecto) lib/ecto/adapters/mysql.ex:181: Ecto.Adapters.MySQL.insert/5 
     (ecto) lib/ecto/repo/schema.ex:381: Ecto.Repo.Schema.apply/4 
     (ecto) lib/ecto/repo/schema.ex:185: anonymous fn/11 in Ecto.Repo.Schema.do_insert/4 
     (ecto) lib/ecto/repo/schema.ex:595: anonymous fn/3 in Ecto.Repo.Schema.wrap_in_transaction/6 
     (ecto) lib/ecto/adapters/sql.ex:472: anonymous fn/3 in Ecto.Adapters.SQL.do_transaction/3 
     (db_connection) lib/db_connection.ex:973: DBConnection.transaction_run/4 
     (db_connection) lib/db_connection.ex:897: DBConnection.run_begin/3 
     (db_connection) lib/db_connection.ex:671: DBConnection.transaction/3 

これではありません他のモデルで起こっています。 モデルスキーマは次のとおりです。

schema "accounts" do 
    field :key, :string, null: false 
    field :cypher_key, :string, null: false 
    field :another_key, :string, null: false 
    field :another_cypher_key, :string, null: false 
    belongs_to :user, MyApp.User 
    timestamps() 
    end 

をし、挿入するときに私がやっている:

Repo.insert! %Account{key: "test", 
         cypher_key: "test", 
         another_key: "test", 
         another_cypher_key: "pk_test" 
      } 

手動でのMySQLを経由して挿入することがうまく動作cmdを。

答えて

0

テーブルにtimestampsフィールドが含まれていますか?そのために適切な移行を生成しましたか?

mix ecto.gen.migrationを使用して、ファイルを開きます(で作成されます)。

def change do 
    create table(:accounts) do 
    add :key, :string 
    # etc. 

    timestamps 
    end 

    create unique_index(:accounts, [:key]) 
end 

その後mix ecto.migrateでこの移行を適用します。

が、これは似たものにchange機能を変更します。

私はそれが役に立ちそうです。

+0

私はそれを逃した、指摘のおかげで。 – David

0

移行ファイルにtimestampsを追加していない可能性があります。 Ecto.Schemaと移行ファイルの両方について、timestamps関数は2つのフィールド、すなわちupdated_atinserted_atを参照します。 Ruby on Railsから来た場合は、created_atという名前の違いに気付くことがあります。詳細については、the docs hereを参照してください。

+0

私はそれを逃した、指摘のおかげで。 – David

関連する問題