4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

mix ecto.migrate で重複エラーが起きた時のメモ【調査中】

Last updated at Posted at 2019-11-05

すいませんものすごく個人的なメモです。

問題

mix ecto.migrateを行った際以下のようなエラーが発生

$ mix ecto.migrate
warning: found quoted keyword "test" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of Unicode letters, numbers, underscore, and @ do not require quotes 
  mix.exs:56

** (Ecto.MigrationError) migrations can't be executed, migration name create_articles is duplicated
    (ecto) lib/ecto/migrator.ex:275: Ecto.Migrator.ensure_no_duplication/1
    (ecto) lib/ecto/migrator.ex:256: Ecto.Migrator.migrate/4
    (ecto) lib/mix/tasks/ecto.migrate.ex:83: anonymous fn/4 in Mix.Tasks.Ecto.Migrate.run/2
    (elixir) lib/enum.ex:783: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir) lib/enum.ex:783: Enum.each/2
    (mix) lib/mix/task.ex:331: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:79: Mix.CLI.run_task/2
    (elixir) lib/code.ex:813: Code.require_file/2

英文ではcreate_articles名が重複しとるぞと

解決法(とりあえず解決法を知りたい人に)

テーブル名が同じ名前のためエラーが出たのこと、
以下のコマンドで通ります。
mix ecto.migrate --step 1

原因

どうやら migrate する際にテーブル名が重複していたようでmigrationを一つに実行すると通るというわけですね。

You can fix it by running 1 migration at a time

mix ecto.migrate --step 1 こちらのコマンドをうつと

$ mix ecto.migrate --step 1
warning: found quoted keyword "test" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of Unicode letters, numbers, underscore, and @ do not require quotes 
  mix.exs:56

[info] == Running App.Repo.Migrations.CreateArticles.change/0 forward
[info] create table articles
[info] == Migrated in 0.1s

やったぜ実行できました!

Ideally you should not have 2 migrations with the same name :)

以下の記事でもあるようにテーブル名は同じ名前じゃだめだよーとのこと
むむーどこで作成しちまっていたのか...
メモでした。

参考リンク

How to fix Ecto duplicate name migrations error
http://disq.us/t/2jnipyj
ありがとう https://github.com/minhajuddin さん

そのほか日本語での mix tasks を解説してくださっている記事です。
Phoenix入門 (第14章 Mix Tasks その2) - 技術メモ
https://www.tech-note.info/entry/phoenix-14-mix-tasks-2#mix-ectogenmigration
ありがたいありがたい

mix tasks は一通り覚えようと思いました...

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?