Migration failed #924

Closed
opened 2025-12-29 02:26:08 +01:00 by adam · 10 comments
Owner

Originally created by @skarpinis on GitHub (Jan 24, 2025).

Is this a support request?

  • This is not a support request

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

2025-01-24T20:51:26Z INF Opening database database=sqlite3 path=/var/lib/headscale/db.sqlite
2025-01-24T20:51:26Z FTL Migration failed: constraint failed: NOT NULL constraint failed: routes__temp.node_id (1299) error="constraint failed: NOT NULL constraint failed: routes__temp.node_id (1299)"

Expected Behavior

working as before

Steps To Reproduce

just updated to new version

Environment

- OS:debian
- Headscale version:0.24.1
- Tailscale version:latest

Runtime environment

  • Headscale is behind a (reverse) proxy
  • Headscale runs in a container

Anything else?

No response

Originally created by @skarpinis on GitHub (Jan 24, 2025). ### Is this a support request? - [x] This is not a support request ### Is there an existing issue for this? - [x] I have searched the existing issues ### Current Behavior 2025-01-24T20:51:26Z INF Opening database database=sqlite3 path=/var/lib/headscale/db.sqlite 2025-01-24T20:51:26Z FTL Migration failed: constraint failed: NOT NULL constraint failed: routes__temp.node_id (1299) error="constraint failed: NOT NULL constraint failed: routes__temp.node_id (1299)" ### Expected Behavior working as before ### Steps To Reproduce just updated to new version ### Environment ```markdown - OS:debian - Headscale version:0.24.1 - Tailscale version:latest ``` ### Runtime environment - [ ] Headscale is behind a (reverse) proxy - [x] Headscale runs in a container ### Anything else? _No response_
adam added the bug label 2025-12-29 02:26:08 +01:00
adam closed this issue 2025-12-29 02:26:09 +01:00
Author
Owner

@kradalby commented on GitHub (Jan 26, 2025):

Can you check with your backup if you have any routes that does not have a Node?

@kradalby commented on GitHub (Jan 26, 2025): Can you check with your backup if you have any routes that does not have a Node?
Author
Owner

@skarpinis commented on GitHub (Jan 27, 2025):

I don't have sorry, just downgraded to 0.24.0 its working fine but latest version not. :(

@skarpinis commented on GitHub (Jan 27, 2025): I don't have sorry, just downgraded to 0.24.0 its working fine but latest version not. :(
Author
Owner

@nblock commented on GitHub (Jan 27, 2025):

I don't have sorry, just downgraded to 0.24.0 its working fine but latest version not. :(

Can you paste the output of the following query with your current database:

select * from routes where node_id not in (select id from nodes);
@nblock commented on GitHub (Jan 27, 2025): > I don't have sorry, just downgraded to 0.24.0 its working fine but latest version not. :( Can you paste the output of the following query with your current database: ```sql select * from routes where node_id not in (select id from nodes); ```
Author
Owner

@skarpinis commented on GitHub (Jan 27, 2025):

I don't have sorry, just downgraded to 0.24.0 its working fine but latest version not. :(

Can you paste the output of the following query with your current database:

select * from routes where node_id not in (select id from nodes);

hi, no output at all

@skarpinis commented on GitHub (Jan 27, 2025): > > I don't have sorry, just downgraded to 0.24.0 its working fine but latest version not. :( > > Can you paste the output of the following query with your current database: > > select * from routes where node_id not in (select id from nodes); hi, no output at all
Author
Owner

@nblock commented on GitHub (Jan 27, 2025):

hi, no output at all

It seems like there is at least one route without a referenced node. Can you please verify with:

select id from routes where node_id is null;
@nblock commented on GitHub (Jan 27, 2025): > hi, no output at all It seems like there is at least one route without a referenced node. Can you please verify with: ```sql select id from routes where node_id is null; ```
Author
Owner

@skarpinis commented on GitHub (Jan 27, 2025):

hi, no output at all

It seems like there is at least one route without a referenced node. Can you please verify with:

select id from routes where node_id is null;

15
16
17
18
20

@skarpinis commented on GitHub (Jan 27, 2025): > > hi, no output at all > > It seems like there is at least one route without a referenced node. Can you please verify with: > > select id from routes where node_id is null; 15 16 17 18 20
Author
Owner

@ryan77627 commented on GitHub (Jan 27, 2025):

I am going to hop in here as well, let me know if you want a separate issue for my migration issue.

Upgraded 0.24.0 -> 0.24.1 and have this issue when starting now:

rnc_headscale  | 2025-01-27T22:40:54Z INF Opening database database=sqlite3 path=/var/lib/headscale/db.sqlite
rnc_headscale  | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=1 table=nodes
rnc_headscale  | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=2 table=nodes
rnc_headscale  | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=3 table=nodes
rnc_headscale  | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=4 table=nodes
rnc_headscale  | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=5 table=nodes
rnc_headscale  | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=6 table=nodes
rnc_headscale  | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=8 table=nodes
rnc_headscale  | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=10 table=nodes
rnc_headscale  | 2025-01-27T22:40:54Z FTL Migration failed: foreign key constraints violated error="foreign key constraints violated"

Going to look into it in a few hours when I get home, but figured I would drop it here as well. Thanks!


Edit (nblock): this is issue https://github.com/juanfont/headscale/issues/2373

@ryan77627 commented on GitHub (Jan 27, 2025): I am going to hop in here as well, let me know if you want a separate issue for my migration issue. Upgraded 0.24.0 -> 0.24.1 and have this issue when starting now: ``` rnc_headscale | 2025-01-27T22:40:54Z INF Opening database database=sqlite3 path=/var/lib/headscale/db.sqlite rnc_headscale | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=1 table=nodes rnc_headscale | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=2 table=nodes rnc_headscale | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=3 table=nodes rnc_headscale | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=4 table=nodes rnc_headscale | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=5 table=nodes rnc_headscale | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=6 table=nodes rnc_headscale | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=8 table=nodes rnc_headscale | 2025-01-27T22:40:54Z ERR Foreign key constraint violated parent=pre_auth_keys row_id=10 table=nodes rnc_headscale | 2025-01-27T22:40:54Z FTL Migration failed: foreign key constraints violated error="foreign key constraints violated" ``` Going to look into it in a few hours when I get home, but figured I would drop it here as well. Thanks! --- Edit (nblock): this is issue https://github.com/juanfont/headscale/issues/2373
Author
Owner

@ryan77627 commented on GitHub (Jan 28, 2025):

I have figured out my issue. Some of my nodes had a auth_key_id of 0 rather than NULL for some reason. Sorry for hijacking this thread, but going to keep this here in case this is an actual issue and someone else runs into this. They were old nodes I haven't touched in a while settings-wise as well... Very odd.

SQL that I used to fix: update nodes set auth_key_id = null where id=n; (where n is the row_id's from the error.)

@ryan77627 commented on GitHub (Jan 28, 2025): I have figured out my issue. Some of my nodes had a `auth_key_id` of 0 rather than NULL for some reason. Sorry for hijacking this thread, but going to keep this here in case this is an actual issue and someone else runs into this. They were old nodes I haven't touched in a while settings-wise as well... Very odd. SQL that I used to fix: `update nodes set auth_key_id = null where id=n;` (where `n` is the row_id's from the error.)
Author
Owner

@nblock commented on GitHub (Jan 28, 2025):

hi, no output at all

It seems like there is at least one route without a referenced node. Can you please verify with:
select id from routes where node_id is null;

15 16 17 18 20

OK, you can fix this by deleting those rows: delete from routes where node_id is null;. The update to 0.24.1 should work afterwards.

You may want to have a look at the routes just in case you want to re-add them later. Be sure to have a backup of the database.

@nblock commented on GitHub (Jan 28, 2025): > > > hi, no output at all > > > > > > It seems like there is at least one route without a referenced node. Can you please verify with: > > select id from routes where node_id is null; > > 15 16 17 18 20 OK, you can fix this by deleting those rows: `delete from routes where node_id is null;`. The update to 0.24.1 should work afterwards. You may want to have a look at the routes just in case you want to re-add them later. Be sure to have a backup of the database.
Author
Owner

@skarpinis commented on GitHub (Jan 28, 2025):

fixed thank you

@skarpinis commented on GitHub (Jan 28, 2025): fixed thank you
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#924