How to change column to nullable with modify in Ecto migration

Sooner or later you'll have to change the null constraint in one of your DB relations. How to do it easily in Ecto?

Table of contents

    Although I came across many different examples where a raw SQL has been used to perform this type of operation in Ecto, it's actually super easy to do it with modify/3 function.

    Let's assume that your migration looks like this:

    create table(:blog_posts) do
      add :title, :string, null: false
      add :intro, :text, null: false
      add :body, :text, null: false
    end

    ... and at some point, you realize that you don't want to force passing the intro column value.

    You can change it easily this way:

    alter table(:blog_posts) do
      modify :intro, :text, null: true, from: :text
    end
    Download our ebook
    Szymon Soppa Web Developer
    Szymon Soppa Curiosum Founder & CEO

    Read more
    on #curiosum blog

    Phoenix LiveView Tutorial: Adding Phoenix PubSub and Pow Authentication to Messenger

    We've already bootstrapped our Phoenix LiveView-based Messenger app's database structure and a first LiveView page.

    This time, we're going to improve real-time communication between the app's users using Phoenix PubSub, and use the Pow library to add secure user authentication.

    As of November 2020, the latest Phoenix LiveView version is 0.14.8 - and the series has been updated to match it!

    5 top-tier companies that use Elixir

    Elixir is a pretty capable language - and it consistently ranks near the top of most loved and wanted languages rankings. It has a large following and some very persuasive preachers as well. But that would not be enough to make me like it – what I need as real proof of its strengths is real businesses that strive with Elixir.

    That’s what this list is all about – a bunch of stories from top companies that chose Elixir and never looked back. Let us show you how its power and versatility shows in practice.