gpt4 book ai didi

elixir - 运行外迁移时出错

转载 作者:行者123 更新时间:2023-12-02 00:54:35 26 4
gpt4 key购买 nike

我是 Elixir 和 Phoenix 的新手。我试图用 mix ecto.migrate 为几个迁移文件运行迁移,但它抛出了这个错误,

18:27:24.471 [info]  == Running FatLobster.Repo.Migrations.CreateRecipeTable.change/0 forward
** (Ecto.MigrationError) cannot execute command outside of block
(ecto) lib/ecto/migration/runner.ex:139: Ecto.Migration.Runner.subcommand/1
_build/dev/lib/fat_lobster/priv/repo/migrations/20160423115340_create_recipe_table.exs:5: FatLobster.Repo.Migrations.CreateRecipeTable.change/0
(stdlib) timer.erl:197: :timer.tc/3
(ecto) lib/ecto/migration/runner.ex:25: Ecto.Migration.Runner.run/6
(ecto) lib/ecto/migrator.ex:121: Ecto.Migrator.attempt/6
(ecto) lib/ecto/migrator.ex:71: anonymous fn/4 in Ecto.Migrator.do_up/4
(ecto) lib/ecto/pool.ex:292: Ecto.Pool.with_rollback/3
(ecto) lib/ecto/adapters/sql.ex:582: Ecto.Adapters.SQL.transaction/8
(ecto) lib/ecto/pool.ex:244: Ecto.Pool.outer_transaction/6
(ecto) lib/ecto/adapters/sql.ex:551: Ecto.Adapters.SQL.transaction/3
(ecto) lib/ecto/migrator.ex:226: anonymous fn/4 in Ecto.Migrator.migrate/4
(elixir) lib/enum.ex:1088: Enum."-map/2-lists^map/1-0-"/2
(ecto) lib/mix/tasks/ecto.migrate.ex:63: anonymous fn/4 in Mix.Tasks.Ecto.Migrate.run/2
(elixir) lib/enum.ex:604: Enum."-each/2-lists^foreach/1-0-"/2
(elixir) lib/enum.ex:604: Enum.each/2
(mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2
(elixir) lib/code.ex:363: Code.require_file/2

这是迁移,

defmodule FatLobster.Repo.Migrations.CreateRecipeTable do
use Ecto.Migration

def change do
add :recipe_title, :string
add :recipe_description, :string

add :cover_img, :string
add :picture_one, :string
add :picture_two, :string
add :picture_three, :string

add :user_id, :integer
add :upvote_count, :integer
add :downvote_count, :integer

timestamps
end
end

现在,这里到底出了什么问题?我真的缺少什么?我应该寻找特定的东西吗?

最佳答案

您缺少 create table(...) block :

defmodule FatLobster.Repo.Migrations.CreateRecipeTable do
use Ecto.Migration

def change do
create table(:recipes) do
add :recipe_title, :string
add :recipe_description, :text
add :cover_img, :string
add :picture_one, :string
add :picture_two, :string
add :picture_three, :string

add :user_id, :integer
add :upvote_count, :integer
add :downvote_count, :integer

timestamps
end
end
end

更多信息在这里:https://hexdocs.pm/ecto/Ecto.Migration.html#create/1

关于elixir - 运行外迁移时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36810881/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com