Error in running priv/repo/seeds.exs
The database for Moba.Repo has already been created
12:42:42.439 [info] Already up
[info] AppSignal disabled.
[debug] QUERY ERROR db=2.9ms queue=0.7ms idle=450.3ms
INSERT INTO "users" ("email","email_confirmation_token","experience","is_admin","is_bot","is_guest","level","medal_count","password_hash","pvp_losses","pvp_points","pvp_score","pvp_wins","shard_count","tutorial_step","username","inserted_at","updated_at") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18) RETURNING "id" ["admin@browsermoba.com", "eae5887f-ae41-4989-811a-2a6f3c0c228c", 0, true, false, false, 20, 0, "$pbkdf2-sha512$100000$0Ktdi/cGImQ6VPJ03SKiTw==$ERZTfHgoHgfhZD1HjdekQdljHSZBt03e2aoAVWc3Z3t8Vyx9zx9p3EdZcmPHeeHpv1fusDPIgrHiYOyfFCPVJQ==", 0, 0, %{}, 0, 100, 0, "Admin", ~N[2020-09-03 04:42:43], ~N[2020-09-03 04:42:43]]
** (Ecto.InvalidChangesetError) could not perform insert because changeset is invalid.
Errors
%{
email: [
{"has already been taken",
[constraint: :unique, constraint_name: "users_email_index"]}
]
}
Applied changes
%{
email: "admin@browsermoba.com",
email_confirmation_token: "eae5887f-ae41-4989-811a-2a6f3c0c228c",
experience: 0,
is_admin: true,
is_bot: false,
is_guest: false,
level: 20,
medal_count: 0,
password: "123456",
password_hash: "$pbkdf2-sha512$100000$0Ktdi/cGImQ6VPJ03SKiTw==$ERZTfHgoHgfhZD1HjdekQdljHSZBt03e2aoAVWc3Z3t8Vyx9zx9p3EdZcmPHeeHpv1fusDPIgrHiYOyfFCPVJQ==",
pvp_losses: 0,
pvp_points: 0,
pvp_score: %{},
pvp_wins: 0,
shard_count: 100,
tutorial_step: 0,
username: "Admin"
}
Params
%{
"email" => "admin@browsermoba.com",
"password" => "123456",
"password_confirmation" => "123456",
"username" => "Admin"
}
Changeset
#Ecto.Changeset<
action: :insert,
changes: %{
email: "admin@browsermoba.com",
email_confirmation_token: "eae5887f-ae41-4989-811a-2a6f3c0c228c",
experience: 0,
is_admin: true,
is_bot: false,
is_guest: false,
level: 20,
medal_count: 0,
password: "123456",
password_hash: "$pbkdf2-sha512$100000$0Ktdi/cGImQ6VPJ03SKiTw==$ERZTfHgoHgfhZD1HjdekQdljHSZBt03e2aoAVWc3Z3t8Vyx9zx9p3EdZcmPHeeHpv1fusDPIgrHiYOyfFCPVJQ==",
pvp_losses: 0,
pvp_points: 0,
pvp_score: %{},
pvp_wins: 0,
shard_count: 100,
tutorial_step: 0,
username: "Admin"
},
errors: [
email: {"has already been taken",
[constraint: :unique, constraint_name: "users_email_index"]}
],
data: #Moba.Accounts.Schema.User<>,
valid?: false
>
(ecto 3.4.2) lib/ecto/repo/schema.ex:169: Ecto.Repo.Schema.insert!/4
priv/repo/seeds.exs:55: (file)
(elixir 1.10.4) lib/code.ex:926: Code.require_file/2
(mix 1.10.4) lib/mix/tasks/run.ex:145: Mix.Tasks.Run.run/5
(mix 1.10.4) lib/mix/tasks/run.ex:85: Mix.Tasks.Run.run/1
(mix 1.10.4) lib/mix/task.ex:330: Mix.Task.run_task/3
(mix 1.10.4) lib/mix/task.ex:364: Mix.Task.run_alias/3
(mix 1.10.4) lib/mix/task.ex:292: Mix.Task.run/2
(mix 1.10.4) lib/mix/cli.ex:82: Mix.CLI.run_task/2
(elixir 1.10.4) lib/code.ex:926: Code.require_file/2
I don’t know why the line 53 through 55 is executed twice. A quick fix could be
...
|> Repo.insert!(on_conflict: :nothing)