JimmyCarterSon

JimmyCarterSon

Seed Data with Elixir

Hello,

I am working on a new application with Elixir, Dish_out. I want to see Data I follow this tutorial with Elixir Casts. However, I am not sure if what I am doing is correct because my seed file does not work.
My Seed File:

alias DishOut.Recipes

Recipes.insert!(
    %{title: "Mac N Cheese", ingredients: "Elbow Pasta, Milk, Cheese, Heavy cream", summary: "Bring pasta to a boil for 10 mins, drain water, add milk, cream, and cheese in. Stir and allow to cool before consuming.", date: "032022"}
)

In video the moderator alias another file, what is that file?

Marked As Solved

kokolegorille

kokolegorille

There is no insert! function in the Food structure. And Foods should be the module used to create Food struct.

You cannot invent function name, it needs to exists in the file.

  @doc """
  Creates a food.
  ## Examples
      iex> create_food(%{field: value})
      {:ok, %Food{}}
      iex> create_food(%{field: bad_value})
      {:error, %Ecto.Changeset{}}
  """
  def create_food(attrs \\ %{}) do
    %Food{}
    |> Food.changeset(attrs)
    |> Repo.insert()
  end

The closest is this one, and should be used like this…

DishOut.Foods.create_food(attrs)

Also Liked

kokolegorille

kokolegorille

Looking at the code… there is no module called Recipes.

One is called Foods, but not Recipes.

Hmm? No error message?

You might test this in the console directly.

JimmyCarterSon

JimmyCarterSon

Yes, Recipes don’t exist. I thought we were creating a new one to seed the file?

What do I reference my Schema which is “Delish_foods”

so would it alias DishOut.Delish_foods?

sorry I am a beginner this si my first time seeding a file in elixir.

kokolegorille

kokolegorille

The github repo You are following looks like a beginner repo too.

The right name should be DishOut.Foods.Food

delish_foods is the name of the table.

PS. I did not watch the screencast, so I don’t know what’s in.

Where Next?

Popular Backend topics Top

DevotionGeo
I know that -t flag is used along with -i flag for getting an interactive shell. But I cannot digest what the man page for docker run com...
New
Ookma-Kyi
I am learning Elixir at the moment but am finding it difficult to learn. The issue is there aren’t any good tutorial sites out there when...
New
sampu
I have a use case where a client is invoking a Rest endpoint via a load balancer, which in turn invokes a third party endpoint which is r...
New
Fl4m3Ph03n1x
Background I am trying to get a Github Action working with Windows and Bakeware because I am trying to create a release using it. Howeve...
New
JimmyCarterSon
I am confused about the Schema setup, I am setting up a new application and I want to seed files in it as well. I tried to mix to create...
New
conradwt
Hi, I’m building an application that will have support for both the web and mobile. At this time, I’m using PhxGenAuth for authenticatio...
New
JimmyCarterSon
Hello, I am working on a new application with Elixir, Dish_out. I want to see Data I follow this tutorial with Elixir Casts. However, I ...
New
sona11
In Java, if I try to do.equals() on a null string, a null pointer error is issued. I’m wondering whether I can perform the following if I...
New
Fl4m3Ph03n1x
Background When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error: * assembling mark...
New
harwind
I have a large SQL database with millions of records, and I’ve identified duplicate entries. What’s the most efficient way to find and re...
New

Other popular topics Top

AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
New
Maartz
Hi folks, I don’t know if I saw this here but, here’s a new programming language, called Roc Reminds me a bit of Elm and thus Haskell. ...
New
AstonJ
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New
PragmaticBookshelf
Author Spotlight Rebecca Skinner @RebeccaSkinner Welcome to our latest author spotlight, where we sit down with Rebecca Skinner, auth...
New
DevotionGeo
I have always used antique keyboards like Cherry MX 1800 or Cherry MX 8100 and almost always have modified the switches in some way, like...
New
CommunityNews
A Brief Review of the Minisforum V3 AMD Tablet. Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New
AstonJ
Curious what kind of results others are getting, I think actually prefer the 7B model to the 32B model, not only is it faster but the qua...
New