How to alter a column name in an Ecto model with a migration?

ElixirEcto

Elixir Problem Overview


Does anyone know of (or can provide) an example of how to alter a table column name using the ecto DSL

I'm guessing I just use mix ecto.gen.migration but then would I just fill in the empty created file with my custom code (if so, how would you edit a column name, the docs show modify to change the column type)

or is there a command line flag I can pass to generate the migration code for me?

Elixir Solutions


Solution 1 - Elixir

You can now do that with Ecto.Migration.rename/3:

rename table(:posts), :title, to: :summary

Solution 2 - Elixir

We don't have an option to rename columns yet. You will need to consult your database documentation and issue a SQL statement with execute.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTheStoneFoxView Question on Stackoverflow
Solution 1 - ElixirBrianView Answer on Stackoverflow
Solution 2 - ElixirJosé ValimView Answer on Stackoverflow