Migration "Applying users.0006_custom_group_model" to 4.0-beta1 fails #9469

Closed
opened 2025-12-29 20:50:19 +01:00 by adam · 3 comments
Owner

Originally created by @tobiasge on GitHub (Apr 11, 2024).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.0-beta1 (89dd423080)

Python Version

3.11

Steps to Reproduce

  1. Netbox setup with 3.7.5 (upgraded from 2.5)
  2. Migrate to v4.0-beta1 (89dd4230807bf5d8f6de586d86120d8148d23eb1)

Expected Behavior

Successful run of all migrations

Observed Behavior

Migration Applying users.0006_custom_group_model fails with this error:

psycopg.errors.ForeignKeyViolation: update or delete on table "auth_group" violates foreign key constraint "auth_group_permissions_group_id_b120cbf9_fk_auth_group_id" on table "auth_group_permissions"
DETAIL:  Key (id)=(10) is still referenced from table "auth_group_permissions".

Table list pre migration: https://gist.github.com/tobiasge/382ec52aaca740b622d480c75f95acf6#file-3-7-5-table-list-txt
Full stack trace: https://gist.github.com/tobiasge/382ec52aaca740b622d480c75f95acf6#file-exception-txt
Table list after migration try: https://gist.github.com/tobiasge/382ec52aaca740b622d480c75f95acf6#file-4-0-beta-table-list-txt

Originally created by @tobiasge on GitHub (Apr 11, 2024). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.0-beta1 (89dd4230807bf5d8f6de586d86120d8148d23eb1) ### Python Version 3.11 ### Steps to Reproduce 1. Netbox setup with 3.7.5 (upgraded from 2.5) 2. Migrate to `v4.0-beta1 (89dd4230807bf5d8f6de586d86120d8148d23eb1)` ### Expected Behavior Successful run of all migrations ### Observed Behavior Migration `Applying users.0006_custom_group_model` fails with this error: ``` psycopg.errors.ForeignKeyViolation: update or delete on table "auth_group" violates foreign key constraint "auth_group_permissions_group_id_b120cbf9_fk_auth_group_id" on table "auth_group_permissions" DETAIL: Key (id)=(10) is still referenced from table "auth_group_permissions". ``` Table list pre migration: https://gist.github.com/tobiasge/382ec52aaca740b622d480c75f95acf6#file-3-7-5-table-list-txt Full stack trace: https://gist.github.com/tobiasge/382ec52aaca740b622d480c75f95acf6#file-exception-txt Table list after migration try: https://gist.github.com/tobiasge/382ec52aaca740b622d480c75f95acf6#file-4-0-beta-table-list-txt
adam added the type: bugstatus: acceptedbetaseverity: high labels 2025-12-29 20:50:19 +01:00
adam closed this issue 2025-12-29 20:50:20 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 15, 2024):

@tobiasge it looks like you have one or more legacy permissions in the auth_group_permissions table referencing the stock Group model. NetBox moved to a custom object-based permission model back in v2.9, and the legacy permissions are no longer used for anything. There was a migration to copy the legacy permissions into the new table but I don't believe the old ones were ever deleted.

Could you try clearing out that table and re-running the v4.0 migration? (DELETE FROM auth_group_permissions in the dbshell should do it.)

@jeremystretch commented on GitHub (Apr 15, 2024): @tobiasge it looks like you have one or more legacy permissions in the `auth_group_permissions` table referencing the stock Group model. NetBox moved to a custom object-based permission model back in v2.9, and the legacy permissions are no longer used for anything. There was a [migration](https://github.com/netbox-community/netbox/blob/v2.9.0/netbox/users/migrations/0009_replicate_permissions.py) to copy the legacy permissions into the new table but I don't believe the old ones were ever deleted. Could you try clearing out that table and re-running the v4.0 migration? (`DELETE FROM auth_group_permissions` in the `dbshell` should do it.)
Author
Owner

@tobiasge commented on GitHub (Apr 16, 2024):

DELETE FROM auth_group_permissions
DELETE 627

After this the Applying users.0006_custom_group_model was successful.

@tobiasge commented on GitHub (Apr 16, 2024): ```sql DELETE FROM auth_group_permissions DELETE 627 ``` After this the `Applying users.0006_custom_group_model` was successful.
Author
Owner

@tobiasge commented on GitHub (Apr 16, 2024):

Just for completeness: I did some research and figured out that the first installation with this database was on Netbox 2.2.9

@tobiasge commented on GitHub (Apr 16, 2024): Just for completeness: I did some research and figured out that the first installation with this database was on Netbox 2.2.9
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9469