Migrations can't be executed, migration name xxx is duplicated

Hello all,
I am in the middle of learning Elixir / Phoenix and doing a project in the Pragmatic Studio project for creating a schema/db for products. However I messed up somewhere and now I am getting this.

migrations can't be executed, migration name create_products is duplicated
Repo: Pento.Repo

  Status    Migration ID    Migration Name
--------------------------------------------------
  down      20231219221534  create_users_auth_tables
  down      20231221215943  create_products
  down      20231228195803  create_products

I tried dropping the database, recreating it, migrating it but still getting the same result. Any ideas?

Thanks

You could look in the priv/repo/migrations folder and delete the unwanted migration

You might list all your migrations with…

ls -1 priv/repo/migrations

Then do

mix ecto.reset
# or
mix ecto.drop
mix ecto.create
mix ecto.migrate

Thanks for responding.

20231219221534_create_users_auth_tables.exs
20231221215943_create_products.exs
20231228195803_create_products.exs

I tried doing mix ecto.reset but got this

The database for Pento.Repo has been dropped
The database for Pento.Repo has been created
** (Ecto.MigrationError) migrations can't be executed, migration name create_products is duplicated

And got the same thing when i tried doing

mix ecto.drop
mix ecto.create
mix ecto.migrate

20231221215943_create_products.exs
20231228195803_create_products.exs

You have two migrations called create_products, you need to delete one of them.

While the file names may be different due to the prefixed timestamp, migrations are generated into modules which doesn’t include the timestamp. This means you have two modules named MyApp.Repo.CreateProducts which is not allowed in Elixir.

3 Likes

The error message is quite explicit :slight_smile:

Yes exactly, maybe prefer to delete the first one, as it should be the wrong one

1 Like

Thank you - i am unsure of the command to delete as I tried a few things. Sorry for the dumb questions, just new to this.

You’re just deleting a file:

rm priv/repo/migrations/20231221215943_create_products.exs

Don’t worry if the questions seem dumb, there’s a lot going through your head in the learning process.

2 Likes

thanks a lot :slight_smile: ill give this a shot

That seemed to work, thanks!