微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决使用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 举报,一经查实,本站将立刻删除。