elbasti
Generating `schema_migrations` table automatically in Livebook with sqlite3
Hi everyone,
I’m trying to run a LiveBook that uses ecto and sqlite.
When I trun to run a migration, I get the following error: ** (Exqlite.Error) no such table: schema_migrations.
I suppose I could create the table manually, but I was wondering if there’s a way it can be created automatically. Since I’m using livebook, I can’t really run the mix tasks.
This is the content of my livebook:
Get Sqlite to work
Mix.install(
[
{:ecto, "~> 3.11"},
{:ecto_sqlite3, "~> 0.13"},
{:ecto_sql, "~> 3.11"},
{:kino, "~> 0.12.3"}
],
config: [
my_app: [
{:ecto_repos, [MyApp.Repo]},
{:"Elixir.MyApp.Repo", [database: :memory]}
]
]
)
Setup Repo
defmodule MyApp.Repo do
use Ecto.Repo,
otp_app: :my_app,
adapter: Ecto.Adapters.SQLite3
end
alias MyApp.Repo
{:ok, repo_pid} = Kino.start_child(Repo)
# Ecto.Adapters.SQL.query!(MyApp.Repo, "create table users (id int)")
defmodule Migrations.AddPositionsTable do
use Ecto.Migration
def up do
create table("positions") do
add(:city, :string, size: 40)
add(:temp_lo, :integer)
add(:temp_hi, :integer)
add(:prcp, :float)
timestamps()
end
end
def down do
drop(table("positions"))
end
end
Ecto.Migrator.run(Repo, [{0, Migrations.AddPositionsTable}], :up, all: true)
Whith this being the entirety of the error message when I try to run the migration:
** (Exqlite.Error) no such table: schema_migrations
SELECT s0."version" FROM "schema_migrations" AS s0
(ecto_sql 3.11.1) lib/ecto/adapters/sql.ex:1054: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto_sql 3.11.1) lib/ecto/adapters/sql.ex:952: Ecto.Adapters.SQL.execute/6
(ecto 3.11.2) lib/ecto/repo/queryable.ex:232: Ecto.Repo.Queryable.execute/4
(ecto 3.11.2) lib/ecto/repo/queryable.ex:19: Ecto.Repo.Queryable.all/3
(ecto_sql 3.11.1) lib/ecto/migrator.ex:586: anonymous fn/5 in Ecto.Migrator.lock_for_migrations/4
(ecto_sql 3.11.1) lib/ecto/migrator.ex:585: Ecto.Migrator.lock_for_migrations/4
(ecto_sql 3.11.1) lib/ecto/migrator.ex:432: Ecto.Migrator.run/4
Any help on how to create the schema_migrations table would be greatly appreciated!
Trending in Questions
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Hello !
We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #elixirconf-us
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security











First 5 of 5 Posts!
D4no0
Sadly, by the nature of how ecto migrations work, you will not be able to use the in-memory option.
Just change the configuration to point to a local file and everything should work as expected.
elbasti
Gotcha. Thank you very much! It’s a bit of a bummer, since in-memory dbs seem like a perfect match for prototyping something in LiveBook.
Appreciate the response!
Any chance you could explain what the issue is, purely for educational purposes?
D4no0
When you start sqlite with in-memory option, the database exists only as long as the process is alive. In this case, ecto currently doesn’t guarantee that migrations will be done in the same process, so when a new process is started there are no migrations left as the database is in memory.
This is a limitation of ecto design as it was more oriented in interacting with persistent databases, maybe it will be fixed in the future, however from what I understand is not that trivial.
DreamEmulator
Seb here, long time lurker and budding fan of this community..
Just wanted to drop in and says thanks for these kinds of answers
It’s so refreshing to see real people really helping each other learn.
Specially now amongst all the AI hype I appreciate it so much more to join a community of really nice real people taking time for each other
adamwight
It can be done with the workaround discussed in this promising open issue, given a connection string likedatabase: ":memory:?cache=shared".Update: It should be possible to use the shared cache but this isn’t quite supported by the Elixir sqlite3 adapter yet.