[GH-ISSUE #3110] migrate from 2.1.2 to 2.2.2 fails #1770

Closed
opened 2026-02-27 11:19:00 +03:00 by kerem · 2 comments
Owner

Originally created by @cyrilst on GitHub (Nov 1, 2023).
Original GitHub issue: https://github.com/modoboa/modoboa/issues/3110

Impacted versions

  • OS Type: Debian
  • OS Version: 11 (bullseye)
  • Database Type: PostgreSQL
  • Database version: 13.11
  • Modoboa: 2.2.2
  • installer used: Yes ?
  • Webserver: Nginx

Steps to reproduce

Install modoboa version 2.1.2, upgrade to 2.2.2.

Current behavior

Installer will not report any error, but the column mb.is_send_only will not be added (the database schema is not correctly upgraded).

When trying to migrate by hand, here is the error:

modoboa@myserver:~/instance$ python3 manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, authtoken, contenttypes, core, django_rq, dmarc, dnstools, imap_migration, lib, limits, maillog, modoboa_amavis, modoboa_contacts, modoboa_postfix_autoreply, modoboa_radicale, otp_static, otp_totp, relaydomains, reversion, sessions, sites, transport
Running migrations:
  Applying admin.0020_auto_20210130_2226...Traceback (most recent call last):
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 87, in _execute
    return self.cursor.execute(sql)
  File "/srv/modoboa/.local/lib/python3.9/site-packages/psycopg/cursor.py", line 737, in execute
    raise ex.with_traceback(None)
psycopg.errors.FeatureNotSupported: cannot alter type of a column used by a view or rule
DETAIL:  rule _RETURN on view dkim depends on column "name"

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

Traceback (most recent call last):
  File "/srv/modoboa/instance/manage.py", line 22, in <module>
    main()
  File "/srv/modoboa/instance/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/core/management/base.py", line 106, in wrapper
    res = handle_func(*args, **kwargs)
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 356, in handle
    post_migrate_state = executor.migrate(
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 252, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/migrations/migration.py", line 132, in apply
    operation.database_forwards(
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/migrations/operations/fields.py", line 235, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 830, in alter_field
    self._alter_field(
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/postgresql/schema.py", line 288, in _alter_field
    super()._alter_field(
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 1055, in _alter_field
    self.execute(
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/postgresql/schema.py", line 48, in execute
    return super().execute(sql, None)
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 201, in execute
    cursor.execute(sql, params)
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 87, in _execute
    return self.cursor.execute(sql)
  File "/srv/modoboa/.local/lib/python3.9/site-packages/psycopg/cursor.py", line 737, in execute
    raise ex.with_traceback(None)
django.db.utils.NotSupportedError: cannot alter type of a column used by a view or rule
DETAIL:  rule _RETURN on view dkim depends on column "name"

Expected behavior

I guess migrate should remove the view, alter the column, and re-add the view after?

Originally created by @cyrilst on GitHub (Nov 1, 2023). Original GitHub issue: https://github.com/modoboa/modoboa/issues/3110 # Impacted versions * OS Type: Debian * OS Version: 11 (bullseye) * Database Type: PostgreSQL * Database version: 13.11 * Modoboa: 2.2.2 * installer used: Yes ? * Webserver: Nginx # Steps to reproduce Install modoboa version 2.1.2, upgrade to 2.2.2. # Current behavior Installer will not report any error, but the column `mb.is_send_only` will not be added (the database schema is not correctly upgraded). When trying to migrate by hand, here is the error: ``` modoboa@myserver:~/instance$ python3 manage.py migrate Operations to perform: Apply all migrations: admin, auth, authtoken, contenttypes, core, django_rq, dmarc, dnstools, imap_migration, lib, limits, maillog, modoboa_amavis, modoboa_contacts, modoboa_postfix_autoreply, modoboa_radicale, otp_static, otp_totp, relaydomains, reversion, sessions, sites, transport Running migrations: Applying admin.0020_auto_20210130_2226...Traceback (most recent call last): File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 87, in _execute return self.cursor.execute(sql) File "/srv/modoboa/.local/lib/python3.9/site-packages/psycopg/cursor.py", line 737, in execute raise ex.with_traceback(None) psycopg.errors.FeatureNotSupported: cannot alter type of a column used by a view or rule DETAIL: rule _RETURN on view dkim depends on column "name" The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/srv/modoboa/instance/manage.py", line 22, in <module> main() File "/srv/modoboa/instance/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/srv/modoboa/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line utility.execute() File "/srv/modoboa/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 436, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/srv/modoboa/.local/lib/python3.9/site-packages/django/core/management/base.py", line 412, in run_from_argv self.execute(*args, **cmd_options) File "/srv/modoboa/.local/lib/python3.9/site-packages/django/core/management/base.py", line 458, in execute output = self.handle(*args, **options) File "/srv/modoboa/.local/lib/python3.9/site-packages/django/core/management/base.py", line 106, in wrapper res = handle_func(*args, **kwargs) File "/srv/modoboa/.local/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 356, in handle post_migrate_state = executor.migrate( File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 135, in migrate state = self._migrate_all_forwards( File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards state = self.apply_migration( File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 252, in apply_migration state = migration.apply(state, schema_editor) File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/migrations/migration.py", line 132, in apply operation.database_forwards( File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/migrations/operations/fields.py", line 235, in database_forwards schema_editor.alter_field(from_model, from_field, to_field) File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 830, in alter_field self._alter_field( File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/postgresql/schema.py", line 288, in _alter_field super()._alter_field( File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 1055, in _alter_field self.execute( File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/postgresql/schema.py", line 48, in execute return super().execute(sql, None) File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 201, in execute cursor.execute(sql, params) File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 67, in execute return self._execute_with_wrappers( File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers return executor(sql, params, many, context) File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/utils.py", line 91, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/srv/modoboa/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 87, in _execute return self.cursor.execute(sql) File "/srv/modoboa/.local/lib/python3.9/site-packages/psycopg/cursor.py", line 737, in execute raise ex.with_traceback(None) django.db.utils.NotSupportedError: cannot alter type of a column used by a view or rule DETAIL: rule _RETURN on view dkim depends on column "name" ``` # Expected behavior I guess migrate should remove the view, alter the column, and re-add the view after?
kerem closed this issue 2026-02-27 11:19:01 +03:00
Author
Owner

@tonioo commented on GitHub (Nov 2, 2023):

@cyrilst This issue was described for 2.0 (https://modoboa.readthedocs.io/en/latest/upgrade.html#migration-issue-for-postgres-opendkim-users) but it seems it can still occur.
The migrate command won't handle this because it is not responsible for creating the view, it is created manually or using the installer.

<!-- gh-comment-id:1790389823 --> @tonioo commented on GitHub (Nov 2, 2023): @cyrilst This issue was described for 2.0 (https://modoboa.readthedocs.io/en/latest/upgrade.html#migration-issue-for-postgres-opendkim-users) but it seems it can still occur. The migrate command won't handle this because it is not responsible for creating the view, it is created manually or using the installer.
Author
Owner

@cyrilst commented on GitHub (Nov 2, 2023):

Thanks for the answer. That was indeed it.

<!-- gh-comment-id:1790497334 --> @cyrilst commented on GitHub (Nov 2, 2023): Thanks for the answer. That was indeed it.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/modoboa-modoboa#1770
No description provided.