Error creating content-type after update from 9.1.2 to 10.0.0

I was using Sentry Python based installation, i decided to use onpremise,

  1. Created a database dump
  2. ran onpremise 9.1.2,
  3. rolled the dump
    when trying to upgrade to 10.0.0, i got this error:
    Running migrations:
    No migrations to apply.
    Traceback (most recent call last):
    File “/usr/local/bin/sentry”, line 8, in
    sys.exit(main())
    File “/usr/local/lib/python2.7/site-packages/sentry/runner/init.py”, line 164, in main
    cli(prog_name=get_prog(), obj={}, max_content_width=100)
    File “/usr/local/lib/python2.7/site-packages/click/core.py”, line 722, in call
    return self.main(*args, **kwargs)
    File “/usr/local/lib/python2.7/site-packages/click/core.py”, line 697, in main
    rv = self.invoke(ctx)
    File “/usr/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File “/usr/local/lib/python2.7/site-packages/click/core.py”, line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
    File “/usr/local/lib/python2.7/site-packages/click/core.py”, line 535, in invoke
    return callback(*args, **kwargs)
    File “/usr/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
    File “/usr/local/lib/python2.7/site-packages/sentry/runner/decorators.py”, line 30, in inner
    return ctx.invoke(f, *args, **kwargs)
    File “/usr/local/lib/python2.7/site-packages/click/core.py”, line 535, in invoke
    return callback(*args, **kwargs)
    File “/usr/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
    File “/usr/local/lib/python2.7/site-packages/sentry/runner/commands/upgrade.py”, line 168, in upgrade
    _upgrade(not noinput, traceback, verbosity, not no_repair)
    File “/usr/local/lib/python2.7/site-packages/sentry/runner/commands/upgrade.py”, line 130, in _upgrade
    ignore_ghost_migrations=True,
    File “/usr/local/lib/python2.7/site-packages/django/core/management/init.py”, line 119, in call_command
    return command.execute(*args, **defaults)
    File “/usr/local/lib/python2.7/site-packages/django/core/management/base.py”, line 399, in execute
    output = self.handle(*args, **options)
    File “/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py”, line 204, in handle
    emit_post_migrate_signal(self.verbosity, self.interactive, connection.alias)
    File “/usr/local/lib/python2.7/site-packages/django/core/management/sql.py”, line 50, in emit_post_migrate_signal
    using=db)
    File “/usr/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py”, line 192, in send
    response = receiver(signal=self, sender=sender, **named)
    File “/usr/local/lib/python2.7/site-packages/django/contrib/auth/management/init.py”, line 85, in create_permissions
    ctype = ContentType.objects.db_manager(using).get_for_model(klass)
    File “/usr/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py”, line 80, in get_for_model
    "Error creating new content types. Please make sure contenttypes "
    RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.
    1
    Cleaning up…
    Any suggestions or comments? :frowning:

Can you provide the commands and details you used to upgrade? Also why not try going to 21.4 directly, instead of 10?

I also tried to upgrade to 21.1.4 but it didn’t work either

  1. Created dump by: psql -U postgres -d sentryX < dump.sql
  2. Downloaded onpremise 9.1.2 and run ./install.sh
  3. Connect to postgres container
  4. DROP DB
  5. CREATE DB
  6. psql -U postgres postgres < dump.sql
  7. run install.sh
  8. downloaded 21.1.4, run ./install.sh and got this error:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/contrib/contenttypes/models.py", line 54, in get_for_model
    ct = self.get(app_label=opts.app_label, model=opts.model_name)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 380, in get
    self.model._meta.object_name
__fake__.DoesNotExist: ContentType matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 464, in get_or_create
    return self.get(**lookup), False
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 380, in get
    self.model._meta.object_name
__fake__.DoesNotExist: ContentType matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/sentry/db/postgres/decorators.py", line 91, in inner
    return func(self, sql, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/sentry/db/postgres/base.py", line 75, in execute
    return self.cursor.execute(sql, clean_bad_params(params))
psycopg2.IntegrityError: null value in column "id" violates not-null constraint
DETAIL:  Failing row contains (null, sentry, alertrule).


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/sentry/db/postgres/decorators.py", line 77, in inner
    raise_the_exception(self.db, e)
  File "/usr/local/lib/python3.6/site-packages/sentry/db/postgres/decorators.py", line 75, in inner
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/sentry/db/postgres/decorators.py", line 18, in inner
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/sentry/db/postgres/decorators.py", line 95, in inner
    raise exc_info[0](msg).with_traceback(exc_info[2])
  File "/usr/local/lib/python3.6/site-packages/sentry/db/postgres/decorators.py", line 91, in inner
    return func(self, sql, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/sentry/db/postgres/base.py", line 75, in execute
    return self.cursor.execute(sql, clean_bad_params(params))
psycopg2.IntegrityError: IntegrityError('null value in column "id" violates not-null constraint\nDETAIL:  Failing row contains (null, sentry, alertrule).\n',)
SQL: INSERT INTO "django_content_type" ("app_label", "model") VALUES (%s, %s) RETURNING "django_content_type"."id"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/bin/sentry", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/sentry/runner/__init__.py", line 195, in main
    func(**kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/sentry/runner/decorators.py", line 29, in inner
    return ctx.invoke(f, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/sentry/runner/commands/upgrade.py", line 171, in upgrade
    _upgrade(not noinput, traceback, verbosity, not no_repair, with_nodestore)
  File "/usr/local/lib/python3.6/site-packages/sentry/runner/commands/upgrade.py", line 127, in _upgrade
    ignore_ghost_migrations=True,
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 131, in call_command
    return command.execute(*args, **defaults)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 227, in handle
    self.verbosity, self.interactive, connection.alias, apps=post_migrate_apps, plan=plan,
  File "/usr/local/lib/python3.6/site-packages/django/core/management/sql.py", line 53, in emit_post_migrate_signal
    **kwargs
  File "/usr/local/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 193, in send
    for receiver in self._live_receivers(sender)
  File "/usr/local/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 193, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/management/__init__.py", line 63, in create_permissions
    ctype = ContentType.objects.db_manager(using).get_for_model(klass)
  File "/usr/local/lib/python3.6/site-packages/django/contrib/contenttypes/models.py", line 60, in get_for_model
    model=opts.model_name,
  File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 466, in get_or_create
    return self._create_object_from_params(lookup, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 509, in _create_object_from_params
    six.reraise(*exc_info)
  File "/usr/local/lib/python3.6/site-packages/django/utils/six.py", line 686, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 500, in _create_object_from_params
    obj = self.create(**params)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 394, in create
    obj.save(force_insert=True, using=self.db)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 808, in save
    force_update=force_update, update_fields=update_fields)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 838, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 924, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 963, in _do_insert
    using=using, raw=raw)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 1079, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1112, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 499, in execute
    return real_execute(self, sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/sentry/db/postgres/decorators.py", line 77, in inner
    raise_the_exception(self.db, e)
  File "/usr/local/lib/python3.6/site-packages/sentry/db/postgres/decorators.py", line 75, in inner
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/sentry/db/postgres/decorators.py", line 18, in inner
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/sentry/db/postgres/decorators.py", line 95, in inner
    raise exc_info[0](msg).with_traceback(exc_info[2])
  File "/usr/local/lib/python3.6/site-packages/sentry/db/postgres/decorators.py", line 91, in inner
    return func(self, sql, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/sentry/db/postgres/base.py", line 75, in execute
    return self.cursor.execute(sql, clean_bad_params(params))
django.db.utils.IntegrityError: IntegrityError('null value in column "id" violates not-null constraint\nDETAIL:  Failing row contains (null, sentry, alertrule).\n',)
SQL: INSERT INTO "django_content_type" ("app_label", "model") VALUES (%s, %s) RETURNING "django_content_type"."id"
1
An error occurred, caught SIGERR on line 12
Cleaning up...

Why do you perform these steps?

Why not?

Because they are not needed?

What should i do?

To upgrade, all you need to do is download or check out the version of onpremise repository you want, replace your existing folder’s contents with that, and then run ./install.sh . We may have some updated configuration, especially for new features, so always check the example config files under the sentry directory

and see if you need to update your existing configuration . We do our best to automate critical configuration updates, but you should always check your configs during upgrades.

Before starting the upgrade, we shut down all the services and then run some data migrations, so expect to have some downtime. There is an experimental --minimize-downtime option to reduce the downtime during upgrades. Use this at your own risk and see the pull request it was implemented in

for more information.

i have NOT on-premise 9.1.2 sentry version without docker

Ah, sorry lost the context from your initial message. Can you try loading your SQL data before ever running ./install.sh when you are switching to 9.1.2?

What is your current Sentry version?