使用insert_all仅插入一条记录,而不是第一条记录

问题描述

我不熟悉使用此堆栈和框架进行开发。我使用的是Ecto 3.4,根据我的理解,阅读文档并查看网上发现的内容,应将所有记录插入到我的单元中。我试过清理,重新编译以及重置数据库。这是在从seed.exs调用的模块中。我非常需要种子数据,因此我想清理它。感觉好像代码很陈旧,因为它插入的唯一记录不是第一个记录,现在有更多记录可以播种。

  def seed do
    timestamp =
      NaiveDateTime.utc_Now()
      |> NaiveDateTime.truncate(:second)

    units = [
      %{abbreviation: "tsp",unit: "teaspoon",standard: "U.S.",inserted_at: timestamp,updated_at: timestamp},%{abbreviation: "tbsp",unit: "tablespoon",%{abbreviation: "oz",unit: "ounces",%{abbreviation: "fl oz",unit: "fluid ounce",%{abbreviation: "cup",unit: "cup",%{abbreviation: "pt",unit: "pint",%{abbreviation: "qt",unit: "quart",%{abbreviation: "gal",unit: "gallon",%{abbreviation: "lb",unit: "pound",%{abbreviation: "l",unit: "liter",standard: "Metric",%{abbreviation: "ml",unit: "milliliter",%{abbreviation: "g",unit: "grams",%{abbreviation: "kg",unit: "kilograms",updated_at: timestamp}
    ]

    Foo.Repo.insert_all(Unit,units)
  end

在这里我有什么错误吗,还是这里有些东西不适合?我已经删除了构建目录。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)