Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration failed #2376

Closed
3 of 4 tasks
skarpinis opened this issue Jan 24, 2025 · 10 comments · Fixed by #2386
Closed
3 of 4 tasks

Migration failed #2376

skarpinis opened this issue Jan 24, 2025 · 10 comments · Fixed by #2386
Labels
bug Something isn't working
Milestone

Comments

@skarpinis
Copy link

skarpinis commented 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

@skarpinis skarpinis added the bug Something isn't working label Jan 24, 2025
@kradalby
Copy link
Collaborator

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

@skarpinis
Copy link
Author

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

@nblock
Copy link
Collaborator

nblock commented 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);

@skarpinis
Copy link
Author

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

@nblock
Copy link
Collaborator

nblock commented 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;

@skarpinis
Copy link
Author

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

@ryan77627
Copy link

ryan77627 commented 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 #2373

@ryan77627
Copy link

ryan77627 commented 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.)

@nblock
Copy link
Collaborator

nblock commented 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 added a commit to nblock/headscale that referenced this issue Jan 28, 2025
The routes table has a NOT NULL constraint on node_id.

Fixes: juanfont#2376
@skarpinis
Copy link
Author

fixed thank you

nblock added a commit to nblock/headscale that referenced this issue Jan 30, 2025
The routes table has a NOT NULL constraint on node_id.

Fixes: juanfont#2376
@nblock nblock added this to the v0.24.2 milestone Jan 30, 2025
kradalby pushed a commit that referenced this issue Jan 30, 2025
The routes table has a NOT NULL constraint on node_id.

Fixes: #2376
kradalby pushed a commit that referenced this issue Jan 30, 2025
The routes table has a NOT NULL constraint on node_id.

Fixes: #2376
socoldkiller pushed a commit to socoldkiller/headscale that referenced this issue Jan 30, 2025
The routes table has a NOT NULL constraint on node_id.

Fixes: juanfont#2376
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants