pinksynth
Hi all! First time posting, let me know if I can structure my question better.
I am using Ecto migrations on a project and need to add columns with non-NULL constraints to a table with existing data. My down simply removes the columns. My up adds the columns, uses default values to get placeholder data in the DB, flushes, and then uses Ecto.Migration.modify/3 to add the non-NULL constraints and remove the defaults. However, when I look at the table description in Postgres, I see not null default NULL::character varying. It looks like the database still behaves properly, but shouldn’t this modifier be gone entirely?
Here’s my migration’s up:
def up do
# Step 1. Add location fields with default values
alter table(:campuses) do
add :street_1, :string, default: "__INVALID_STREET"
add :street_2, :string
add :city, :string, default: "__INVALID_CITY"
add :state, :string, size: 2, default: "ZZ"
add :zip, :string, size: 16, default: "__INVALID_CITY"
add :lon, :float, default: 0.0
add :lat, :float, default: 0.0
end
# Step 2. Execute above commands.
flush()
# Step 3. Remove default option and add null constraint
alter table(:campuses) do
modify :street_1, :string, null: false, default: nil
modify :street_2, :string
modify :city, :string, null: false, default: nil
modify :state, :string, size: 2, null: false, default: nil
modify :zip, :string, size: 16, null: false, default: nil
modify :lon, :float, null: false, default: nil
modify :lat, :float, null: false, default: nil
end
end
Thanks all!
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #ai
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
Have you tried simply removing the
default: niloptions and re-run the migration?florish
@pinksynth It’s been a while, but did you find a solution for this?
joddm
From Postgres documentation
pinksynth
@florish Thanks for asking! It has been a long time, I do not recall what the solution was. In retrospect I embarrassingly don’t really understand the problem either
. Perhaps there is some difference between “No default” and “Default: null”, but I don’t think that difference had any practical impact on the project or code. Thanks @joddm for the docs reference.
florish
Yes, well, that’s a good question indeed. Out of curiosity, I’ve checked the PostgreSQL documentation, and it’s mostly a difference between an implicit
NULL(which is the default if noDEFAULTis set in PostgreSQL) and an explicitNULLdefault value:So practically no impact, the only difference is the presence / absence of an expliciet
DEFAULT NULLstatement in yourCREATE TABLESQL code.dimitarvp
I can confirm that this worked for me in a migration. I needed to change the type of a column so I did the dance with making a new column, migrating the data from the old one to the new one but the new one had to allow a default value because the migration was multi-step and then when everything was done I made a migration to delete the old column and to remove the default value from the new column while still disallowing
NULL/nil.