ecto_mnesia
ecto_mnesia copied to clipboard
Why am I getting `:no_exists on :id_seq`
test/models/user_test.exs:42
** (exit) {:aborted, {:no_exists, :id_seq}}
stacktrace:
(mnesia) mnesia.erl:318: :mnesia.abort/1
(mnesia) mnesia.erl:1610: :mnesia.do_dirty_update_counter/4
(ecto_mnesia) lib/ecto_mnesia/adapter.ex:239: anonymous fn/2 in Ecto.Mnesia.Adapter.put_new_pk/3
(elixir) lib/keyword.ex:242: Keyword.get_and_update/4
(ecto_mnesia) lib/ecto_mnesia/adapter.ex:238: Ecto.Mnesia.Adapter.put_new_pk/3
(ecto_mnesia) lib/ecto_mnesia/adapter.ex:222: Ecto.Mnesia.Adapter.do_insert/4
(ecto) lib/ecto/repo/schema.ex:459: Ecto.Repo.Schema.apply/4
(ecto) lib/ecto/repo/schema.ex:198: anonymous fn/11 in Ecto.Repo.Schema.do_insert/4
test/models/user_test.exs:43: (test)
my migration is (I've tried :set as well)
create_if_not_exists table(:users) do
add :email, :string
add :password_hash, :string
timestamps()
end
I see an id_seq table in mnesia, but it is empty. Does it need to be seeded with something or did I do something else wrong? Thanks for the help.
Can you show what shell commands do you run? Basically whenever a table is created we should insert a new record into id_seq table that will store sequence number. And it looks like record or whole table does not exist (was not created on migration).
@AndrewDryga #27: mix ecto.migrate then running my umbrella project with mix phx.server when i do then insert/get whatever something I get the id_seq error
edit: @AndrewDryga if you need anymore infos please tell me and btw im using windows 10
@AndrewDryga might help: https://github.com/gallexme/ElixirTest
@gallexme thanks, I'll look into it.
@gallexme you need to create directory for Mnesia files first, try to call mix ecto.create. If it fails, just manually create this path. (You can persist in in git by adding empty .gitkeep file into it.)
Also you will need to add config :crypto_exchange_web, ecto_repos: [] to crypto_exchange_web application, to tell ecto migrator that you don't have repos in this app.
The Patch exists on my pc and Actually what I found out is that when I use the Mix task it create The folder under crypto_exchange_data/priv And when I run The umbrella and use mnesia.info it shows a different Patch umbrella/priv
And the other issue is just a warning it shouldnt matter as the Web App doesn't even have ecto
Sorry was written on my phone Patch means path
I'm getting this similar error {:aborted, {:no_exists, :id_seq}}
In my case the error is triggered when starting my node named.
# It works
$ elixir --cookie cookie123 -S mix phoenix.server
# Does not work (triggers the error)
$ elixir --name [email protected] --cookie cookie123 -S mix phoenix.server
This is a serious limitation, and it should probably be addressed!
Cheers!
@walkr try to:
- run migrations from named instance;
- set a custom Mnesia dir. Mnesia stores data in folder with host name, and when you change host name maybe it just don't see migrated DB schema;
- try
snameinstead ofname.
In general, It's not an adapter limitation, rather you should dig deeper into Mnesia details.
@AndrewDryga Thanks!
I've actually ended up fixing the problem, but bumped into another one.
I've solved the problem by supplying the settings on the adapter in the config.exs instead of :ecto_mnesia as it is suggested in the README.
Example
config :my_app, MyApp.Mnesia.Repo,
adapter: EctoMnesia.Adapter,
priv: "priv/repo_mnesia",
host: {:system, :atom, "MNESIA_HOST", Kernel.node()},
storage_type: {:system, :atom, "MNESIA_STORAGE_TYPE", :disc_copies}
However, now I'm bumping into the same {:aborted, {:no_exists, :id_seq}} when I'm using ram_copies.
For RAM copies you need to make sure that you run migrations on each time Erlang VM node starts. And this is a adapters part that could be automated. I'll add separate issue for it.