---
title: "Discussion on \"Everything Migrated, Except the Sequence\" | Hashnode"
description: "Discussion on \"Everything Migrated, Except the Sequence\". A lesson learned from migrating an existing database and overlooking its sequence state."
url: "https://hashnode.com/posts/everything-migrated-except-the-sequence/6b06ea4ceb861040fec83384"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Everything Migrated, Except the Sequence](https://noctilucent.hashnode.dev/everything-migrated-except-the-sequence?utm_source=hashnode&utm_medium=feed)

A lesson learned from migrating an existing database and overlooking its sequence state.

1d ago · 11 min read · noctilucent.hashnode.dev  
Read the article

-   [#postgresql](https://hashnode.com/tag/postgresql)
-   [#django](https://hashnode.com/tag/django)
-   [#database](https://hashnode.com/tag/database)
-   [#python](https://hashnode.com/tag/python)
-   [#migration](https://hashnode.com/tag/migration)

## Written by

[Night Purr](https://hashnode.com/@nightpurr)

@nightpurr

  
[View profile](https://hashnode.com/@nightpurr)

Just building things and sharing what I learn.

Hey there! 👋 I'm a Full-Stack Developer who enjoys exploring how things work, experimenting with ideas, and bringing them to life. Outside of coding, I have a soft spot for mathematics, learning new things, and sharing what I discover. This blog is where I share what I learn, write about things I'm building, and occasionally wander into topics beyond programming. Thanks for stopping by! 😄

## Responses 1

Markdown supported · ⌘↵ to post

[AI Developer](https://hashnode.com/@lycore)

[1h ago](https://hashnode.com/posts/everything-migrated-except-the-sequence/6b06ea4ceb861040fec83384/comment/6b084f488a6d7897ac059430)

Good reminder that copying explicit IDs bypasses nextval(), so the sequence never advances. Two small additions: pg\_get\_serial\_sequence('public.products','id') avoids hardcoding the sequence name in the setval call, and Django ships `manage.py sqlsequencereset <app>` to generate exactly these statements after a manual data load. It could also be worth adding a post-migration check that compares MAX(id) with the sequence's last\_value for every serial column, so this fails in staging instead of showing up as intermittent save errors. Did you consider IDENTITY columns for the new schema? They behave the same way when you insert explicit values, so the same resync step applies.
