# 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:** 3

<div class="post-metadata">

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

</div>

> [@APB9785](#):
>
> ```elixir
> alter table(:table_name) do
> remove :column_name
> add :column_name, :integer
> end
> 
> ```

I believe that would remove all the data under `:column_name`

You can use [modify/3](https://hexdocs.pm/ecto_sql/Ecto.Migration.html#modify/3)

```elixir
alter table("posts") do
  modify :title, :text
end

```

But you still need to handle typecasting the actual data in that column

See this thread [Ecto Changeset: modify column type from :string to {:array, :string}](https://forum.elixirforum.com/t/ecto-changeset-modify-column-type-from-string-to-array-string/32209)

---

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