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!