Skip to content

Commit

Permalink
update adding columns
Browse files Browse the repository at this point in the history
  • Loading branch information
isabellaenriquez committed Dec 17, 2024
1 parent 76196d9 commit dbcd4e2
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,12 @@ With postgres 14, columns can be added to tables of all sizes as deploy time
migrations if you follow the guidelines on default values & allowing nulls. When
creating new columns they should either be:

- Not null with a default. https://develop.sentry.dev/database-migrations/#adding-not-null-to-columns
- Not null with a default
- Created as nullable. If no default value can be set on the column, then it's best just to make it nullable.

For nullable columns with a constraint and not null columns with a default, see [Adding Constraints to Columns](#adding-constraints-to-columns-including-not-null). For bigger tables, these constraints can lock the table and cause downtime.


### Adding Columns With a Default

Since we run Postgres >= 14 in production we are able to add columns with a default. To do so, instead of using `default=<your_default>`, use `db_default=<your_default>`. This tells Django to set a default at the database level and manage it there, rather than managing it in application code.
Expand Down

0 comments on commit dbcd4e2

Please sign in to comment.