Since I need to work with MySql instead of Postgresql I tried to replace the appropriate sections in the tutorial with what was needed. When I get to the mix ecto.create I get the following error:
config :friends, ecto_repos: [Friends.Repo],
database: "friends_repo",
username: "root",
password: "",
hostname: "LocalDB", note: the example has localhost but it failed with that and my HeidiSql shows LocalDB
port: 3306
This is my repo.ex
defmodule Friends.Repo do
use Ecto.Repo,
otp_app: :friends,
adapter: Ecto.Adapters.MyXQL
end
and my application.ex
def start(_type, _args) do
children = [
{MyXQL, username: "root", name: :myxql} Note: this was recommended by the git documentation
]
config :friends, ecto_repos: [Friends.Repo]
config :friends, Friends.Repo,
database: "friends_repo",
username: "root",
password: "",
hostname: "LocalDB", note: the example has localhost but it failed with that and my HeidiSql shows LocalDB
port: 3306
Basically, all you would have had to do was changing dependencies, providing different database credentials and using a different adapter in your Repo. Let us know if it helps!
Success!!! I don’t understand everything that is going on here yet, but my goal was to get the Ecto to talk to MySql and it did create the database. The instructions are confusing, and I would like to see a simpler approach for the rank beginner.
This is from the Ecto Getting started tutorial.
Here are the successful files:
Here is the config.exs
defmodule Friends.Repo do
use Ecto.Repo,
otp_app: :friends,
adapter: Ecto.Adapters.MyXQL
end
And here is the application.ex
defmodule Friends.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
def start(_type, _args) do
children = [
Friends.Repo
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Friends.Supervisor]
Supervisor.start_link(children, opts)
end
end