# Convert string column to integer in DB

**URL:** <https://forum.elixirforum.com/t/convert-string-column-to-integer-in-db/38521>\
**Category:** Questions\
**Tags:** ecto, phoenix, ecto-migration\
**Created:** [March 27, 2021, 4:04pm UTC](https://forum.elixirforum.com/t/convert-string-column-to-integer-in-db/38521 "2021-03-27T16:04:26Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![APB9785](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/apb9785/32/24101_2.png) [@APB9785](https://forum.elixirforum.com/u/APB9785)\
**Post date:** [March 27, 2021, 4:24pm UTC](https://forum.elixirforum.com/t/convert-string-column-to-integer-in-db/38521/2 "2021-03-27T16:24:39Z")

</div>

Make a new migration file (in priv/repo/migrations) like:

```elixir
defmodule YourApp.Repo.Migrations.StrToInt do
  use Ecto.Migration

  def change do
    alter table(:table_name) do
      remove :column_name
      add :column_name, :integer
    end
  end
end

```

Then run mix ecto.migrate

---

_[View the full topic](https://forum.elixirforum.com/t/convert-string-column-to-integer-in-db/38521)._
