Home > Mobile >  Elixir, phoenix, ecto : can't add data to my tables
Elixir, phoenix, ecto : can't add data to my tables

Time:10-26

I am trying to add rows to the table 'users' I have created, but I get this error:

iex(3)> user = %User{username: "mel", email: "mail"}
%Theme01.User{
  __meta__: #Ecto.Schema.Metadata<:built, "user">,
  id: nil,
  email: "mail",
  username: "mel",
  clocks: #Ecto.Association.NotLoaded<association :clocks is not loaded>,
  inserted_at: nil,
  updated_at: nil
}
iex(4)> user = Repo.insert(User)
** (FunctionClauseError) no function clause matching in Ecto.Repo.Schema.insert/4

    The following arguments were given to Ecto.Repo.Schema.insert/4:

        # 1
        Theme01.Repo

        # 2
        Theme01.Repo

        # 3
        Theme01.User

        # 4
        {%{
           adapter: Ecto.Adapters.Postgres,
           cache: #Reference<0.388300084.2616328193.258496>,
           opts: [
             repo: Theme01.Repo,
             timeout: 15000,
             pool_size: 10,
             pool: DBConnection.ConnectionPool
           ],
           pid: #PID<0.402.0>,
           repo: Theme01.Repo,
           sql: Ecto.Adapters.Postgres.Connection,
           stacktrace: true,
           telemetry: {Theme01.Repo, :debug, [:theme01, :repo, :query]}
         },
         [
           stacktrace: [
             {Ecto.Repo.Supervisor, :tuplet, 2,
              [file: 'lib/ecto/repo/supervisor.ex', line: 162]},
             {Theme01.Repo, :insert, 2, [file: 'lib/theme01/repo.ex', line: 2]},
             {:elixir, :"-eval_external_handler/1-fun-2-", 4,
              [file: 'src/elixir.erl', line: 298]},
             {:erl_eval, :do_apply, 7, [file: 'erl_eval.erl', line: 748]},
             {:erl_eval, :expr, 6, [file: 'erl_eval.erl', line: 492]},
             {:elixir, :eval_forms, 3, [file: 'src/elixir.erl', line: 288]},
             {Module.ParallelChecker, :verify, 1,
              [file: 'lib/module/parallel_checker.ex', line: 107]},
             {IEx.Evaluator, :eval_and_inspect, 3,
              [file: 'lib/iex/evaluator.ex', line: 329]},
             {IEx.Evaluator, :eval_and_inspect_parsed, 3,
              [file: 'lib/iex/evaluator.ex', line: 303]},
             {IEx.Evaluator, :parse_eval_inspect, 3,
              [file: 'lib/iex/evaluator.ex', line: 292]},
             {IEx.Evaluator, :loop, 1, [file: 'lib/iex/evaluator.ex', line: 187]},
             {IEx.Evaluator, :init, 4, [file: 'lib/iex/evaluator.ex', line: 32]},
             {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 240]}
           ]
         ]}

    Attempted function clauses (showing 2 out of 2):

        def insert(repo, name, -           
  • Related