【发布时间】:2016-08-09 19:45:07
【问题描述】:
使用 Elixir + Phoenix 将模型插入 MySQL 数据库时,我得到:
** (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 手动插入时,它可以正常工作。
【问题讨论】:
标签: mysql elixir phoenix-framework