Skip to content

fix non-nullable column for existing rows with server default#695

Merged
lnovitz merged 1 commit into
mainfrom
feat/691-add-active-subscription-fields
Dec 28, 2025
Merged

fix non-nullable column for existing rows with server default#695
lnovitz merged 1 commit into
mainfrom
feat/691-add-active-subscription-fields

Conversation

@lnovitz
Copy link
Copy Markdown
Collaborator

@lnovitz lnovitz commented Dec 28, 2025

Pull Request

Description

Failed deployment after enabling alembic in #693

CleanShot 2025-12-27 at 23 44 55

The error you are seeing—psycopg2.errors.NotNullViolation: column "is_active" of relation "users" contains null values—occurs because you are trying to add a non-nullable column to a table that already contains data.

Why this is happening

The Constraint: Your migration 79b431f2e2f8_add_active_beta_billing_status.py is attempting to execute ALTER TABLE users ADD COLUMN is_active BOOLEAN NOT NULL.

Existing Data: Your users table already has rows in it. When the database adds the new is_active column, it doesn't know what value to assign to these existing rows, so it defaults to NULL.

The Conflict: Since you specified nullable=False, the database rejects the operation because those existing rows would immediately violate the "Not Null" rule.

How to Fix It

To fix this, you need to tell the database what value to use for existing rows. You can do this by adding a server_default in your migration file.

Go to the migration file mentioned in your logs (/app/alembic/versions/79b431f2e2f8_add_active_beta_billing_status.py) and update the upgrade() function:

Recommended Fix: Use server_default


By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.

@lnovitz
Copy link
Copy Markdown
Collaborator Author

lnovitz commented Dec 28, 2025

I would have caught this if I had created a new user prior to upgrading my local database to the new migration, then upgraded.

@lnovitz lnovitz merged commit 0524e41 into main Dec 28, 2025
9 checks passed
@lnovitz lnovitz deleted the feat/691-add-active-subscription-fields branch December 28, 2025 07:48
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Just a Job App Dec 28, 2025
@lnovitz lnovitz linked an issue Dec 28, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Update the User Model For Launch

1 participant