Migration db failed (0917_convert_org_saved_searches_to_views) from 25.5.1 to nightly
Self-Hosted Version
25.5.1
CPU Architecture
x86_64
Docker Version
26.1.4
Docker Compose Version
2.32.4
Machine Specification
- [x] My system meets the minimum system requirements of Sentry
Steps to Reproduce
My current version is 25.5.1, which is ok. But after I pull the latest repo (which is nightly), the db migration failed.
Expected Result
The migration should be executed without this error.
Actual Result
Running migrations:
Applying sentry.0917_convert_org_saved_searches_to_views...Saved Searchs
Traceback (most recent call last):
File "/.venv/lib/python3.13/site-packages/django/db/models/query.py", line 946, in get_or_create
return self.get(**kwargs), False
~~~~~~~~^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/django/db/models/query.py", line 633, in get
raise self.model.DoesNotExist(
"%s matching query does not exist." % self.model._meta.object_name
)
__fake__.GroupSearchView.DoesNotExist: GroupSearchView matching query does not exist.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/sentry/src/sentry/db/postgres/decorators.py", line 91, in inner
return func(self, sql, *args, **kwargs)
File "/usr/src/sentry/src/sentry/db/postgres/base.py", line 84, in execute
return self.cursor.execute(sql, clean_bad_params(params))
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.NotNullViolation: null value in column "user_id" of relation "sentry_groupsearchview" violates not-null constraint
DETAIL: Failing row contains (3, 2025-06-05 13:36:09.81613+00, 2019-09-27 07:14:01.029456+00, Unresolved Issues, null, is:unresolved, date, null, {}, f, {"period": "14d"}, organization).
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/.venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "/usr/src/sentry/src/sentry/db/postgres/decorators.py", line 77, in inner
raise_the_exception(self.db, e)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
File "/usr/src/sentry/src/sentry/db/postgres/decorators.py", line 75, in inner
return func(self, *args, **kwargs)
File "/usr/src/sentry/src/sentry/db/postgres/decorators.py", line 18, in inner
return func(self, *args, **kwargs)
File "/usr/src/sentry/src/sentry/db/postgres/decorators.py", line 93, in inner
raise type(e)(f"{e!r}\nSQL: {sql}").with_traceback(e.__traceback__)
File "/usr/src/sentry/src/sentry/db/postgres/decorators.py", line 91, in inner
return func(self, sql, *args, **kwargs)
File "/usr/src/sentry/src/sentry/db/postgres/base.py", line 84, in execute
return self.cursor.execute(sql, clean_bad_params(params))
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.NotNullViolation: NotNullViolation('null value in column "user_id" of relation "sentry_groupsearchview" violates not-null constraint\nDETAIL: Failing row contains (3, 2025-06-05 13:36:09.81613+00, 2019-09-27 07:14:01.029456+00, Unresolved Issues, null, is:unresolved, date, null, {}, f, {"period": "14d"}, organization).\n')
SQL: INSERT INTO "sentry_groupsearchview" ("date_updated", "date_added", "name", "user_id", "visibility", "query", "query_sort", "is_all_projects", "environments", "time_filters", "organization_id") VALUES (%s, %s, %s, %s, DEFAULT, %s, %s, DEFAULT, %s::text[], DEFAULT, %s) RETURNING "sentry_groupsearchview"."id", "sentry_groupsearchview"."visibility", "sentry_groupsearchview"."is_all_projects", "sentry_groupsearchview"."time_filters"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/.venv/bin/sentry", line 4, in <module>
raise SystemExit(main())
~~~~^^
File "/usr/src/sentry/src/sentry/runner/main.py", line 145, in main
func(**kwargs)
~~~~^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/click/core.py", line 1442, in __call__
return self.main(*args, **kwargs)
~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/click/core.py", line 1363, in main
rv = self.invoke(ctx)
File "/.venv/lib/python3.13/site-packages/click/core.py", line 1830, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/click/core.py", line 1226, in invoke
return ctx.invoke(self.callback, **ctx.params)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/click/core.py", line 794, in invoke
return callback(*args, **kwargs)
File "/.venv/lib/python3.13/site-packages/click/decorators.py", line 34, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/src/sentry/src/sentry/runner/decorators.py", line 34, in inner
return ctx.invoke(f, *args, **kwargs)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/click/core.py", line 794, in invoke
return callback(*args, **kwargs)
File "/usr/src/sentry/src/sentry/runner/commands/upgrade.py", line 157, in upgrade
_upgrade(
~~~~~~~~^
not noinput,
^^^^^^^^^^^^
...<5 lines>...
create_kafka_topics,
^^^^^^^^^^^^^^^^^^^^
)
^
File "/usr/src/sentry/src/sentry/runner/commands/upgrade.py", line 72, in _upgrade
dj_call_command(
~~~~~~~~~~~~~~~^
"migrate",
^^^^^^^^^^
...<3 lines>...
verbosity=verbosity,
^^^^^^^^^^^^^^^^^^^^
)
^
File "/.venv/lib/python3.13/site-packages/django/core/management/__init__.py", line 194, in call_command
return command.execute(*args, **defaults)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/django/core/management/base.py", line 460, in execute
output = self.handle(*args, **options)
File "/.venv/lib/python3.13/site-packages/django/core/management/base.py", line 107, in wrapper
res = handle_func(*args, **kwargs)
File "/.venv/lib/python3.13/site-packages/django/core/management/commands/migrate.py", line 353, in handle
post_migrate_state = executor.migrate(
targets,
...<3 lines>...
fake_initial=fake_initial,
)
File "/.venv/lib/python3.13/site-packages/django/db/migrations/executor.py", line 135, in migrate
state = self._migrate_all_forwards(
state, plan, full_plan, fake=fake, fake_initial=fake_initial
)
File "/.venv/lib/python3.13/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
state = self.apply_migration(
state, migration, fake=fake, fake_initial=fake_initial
)
File "/usr/src/sentry/src/sentry/new_migrations/monkey/executor.py", line 154, in apply_migration
return super().apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/django/db/migrations/executor.py", line 255, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/src/sentry/src/sentry/new_migrations/migrations.py", line 28, in apply
return super().apply(project_state, schema_editor, collect_sql)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/django/db/migrations/migration.py", line 132, in apply
operation.database_forwards(
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
self.app_label, schema_editor, old_state, project_state
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/.venv/lib/python3.13/site-packages/django/db/migrations/operations/special.py", line 196, in database_forwards
self.code(from_state.apps, schema_editor)
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/sentry/src/sentry/migrations/0917_convert_org_saved_searches_to_views.py", line 22, in convert_org_saved_searches_to_views
GroupSearchView.objects.update_or_create(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
organization=saved_search.organization,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<6 lines>...
},
^^
)
^
File "/.venv/lib/python3.13/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/django/db/models/query.py", line 988, in update_or_create
obj, created = self.select_for_update().get_or_create(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
create_defaults, **kwargs
^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/.venv/lib/python3.13/site-packages/django/db/models/query.py", line 953, in get_or_create
return self.create(**params), True
~~~~~~~~~~~^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/django/db/models/query.py", line 663, in create
obj.save(force_insert=True, using=self.db)
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/django/db/models/base.py", line 902, in save
self.save_base(
~~~~~~~~~~~~~~^
using=using,
^^^^^^^^^^^^
...<2 lines>...
update_fields=update_fields,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/.venv/lib/python3.13/site-packages/django/db/models/base.py", line 1008, in save_base
updated = self._save_table(
raw,
...<4 lines>...
update_fields,
)
File "/.venv/lib/python3.13/site-packages/django/db/models/base.py", line 1169, in _save_table
results = self._do_insert(
cls._base_manager, using, fields, returning_fields, raw
)
File "/.venv/lib/python3.13/site-packages/django/db/models/base.py", line 1210, in _do_insert
return manager._insert(
~~~~~~~~~~~~~~~^
[self],
^^^^^^^
...<3 lines>...
raw=raw,
^^^^^^^^
)
^
File "/.venv/lib/python3.13/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/django/db/models/query.py", line 1864, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/django/db/models/sql/compiler.py", line 1882, in execute_sql
cursor.execute(sql, params)
~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/sentry_sdk/utils.py", line 1811, in runner
return sentry_patched_function(*args, **kwargs)
File "/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/django/__init__.py", line 651, in execute
result = real_execute(self, sql, params)
File "/.venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 79, in execute
return self._execute_with_wrappers(
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
sql, params, many=False, executor=self._execute
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/.venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/.venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 100, in _execute
with self.db.wrap_database_errors:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.venv/lib/python3.13/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/.venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "/usr/src/sentry/src/sentry/db/postgres/decorators.py", line 77, in inner
raise_the_exception(self.db, e)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
File "/usr/src/sentry/src/sentry/db/postgres/decorators.py", line 75, in inner
return func(self, *args, **kwargs)
File "/usr/src/sentry/src/sentry/db/postgres/decorators.py", line 18, in inner
return func(self, *args, **kwargs)
File "/usr/src/sentry/src/sentry/db/postgres/decorators.py", line 93, in inner
raise type(e)(f"{e!r}\nSQL: {sql}").with_traceback(e.__traceback__)
File "/usr/src/sentry/src/sentry/db/postgres/decorators.py", line 91, in inner
return func(self, sql, *args, **kwargs)
File "/usr/src/sentry/src/sentry/db/postgres/base.py", line 84, in execute
return self.cursor.execute(sql, clean_bad_params(params))
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.IntegrityError: NotNullViolation('null value in column "user_id" of relation "sentry_groupsearchview" violates not-null constraint\nDETAIL: Failing row contains (3, 2025-06-05 13:36:09.81613+00, 2019-09-27 07:14:01.029456+00, Unresolved Issues, null, is:unresolved, date, null, {}, f, {"period": "14d"}, organization).\n')
SQL: INSERT INTO "sentry_groupsearchview" ("date_updated", "date_added", "name", "user_id", "visibility", "query", "query_sort", "is_all_projects", "environments", "time_filters", "organization_id") VALUES (%s, %s, %s, %s, DEFAULT, %s, %s, DEFAULT, %s::text[], DEFAULT, %s) RETURNING "sentry_groupsearchview"."id", "sentry_groupsearchview"."visibility", "sentry_groupsearchview"."is_all_projects", "sentry_groupsearchview"."time_filters"
Error in install/set-up-and-migrate-database.sh:22.
'$dcr web upgrade --create-kafka-topics' exited with status 1
-> ./install.sh:main:41
--> install/set-up-and-migrate-database.sh:source:22
Cleaning up...
Event ID
No response
cc @hubertdeng123 @asottile-sentry
@aldy505 you'll want to track down the migration author -- hubert and I have very little knowledge on the actual contents of the codebase
~~Okay, I believe this is for MichaelSun48~~
EDIT: The guy leaved Sentry
@myonlylonely have you tried upgrading to 25.6.0? Does the issue persist?
@aldy505 Yes, I just tried to upgrade to the latest nightly, it is still the same
I honestly wonder why this happened, since your error here:
psycopg2.errors.NotNullViolation: NotNullViolation('null value in column "user_id" of relation "sentry_groupsearchview" violates not-null constraint\nDETAIL: Failing row contains (3, 2025-06-05 13:36:09.81613+00, 2019-09-27 07:14:01.029456+00, Unresolved Issues, null, is:unresolved, date, null, {}, f, {"period": "14d"}, organization).\n')
SQL: INSERT INTO "sentry_groupsearchview" ("date_updated", "date_added", "name", "user_id", "visibility", "query", "query_sort", "is_all_projects", "environments", "time_filters", "organization_id") VALUES (%s, %s, %s, %s, DEFAULT, %s, %s, DEFAULT, %s::text[], DEFAULT, %s) RETURNING "sentry_groupsearchview"."id", "sentry_groupsearchview"."visibility", "sentry_groupsearchview"."is_all_projects", "sentry_groupsearchview"."time_filters"
Is the same error as this issue: https://github.com/getsentry/self-hosted/issues/3766. Can you try to lock your version to 25.6.1 instead of nightly?
I updated with nightly again just now, and now it is fixed!