Skip to content
Odoo Migration

Odoo Database Migration: Managing Sequence Numbers and ID Conflicts

Learn how to prevent data corruption during Odoo migrations by managing sequence numbers and ID conflicts. A practical guide for CIOs and IT directors on safe database upgrades.

7 min readSysGenPro Editorial
Odoo Database Migration: Managing Sequence Numbers and ID Conflicts

Direct Answer: Preventing ID Conflicts in Odoo Migrations

Managing sequence numbers and ID conflicts is critical during Odoo database migrations to prevent data corruption, broken foreign key relationships, and application errors. The recommended approach involves a rigorous pre-migration audit of all auto-incrementing sequences, a controlled synchronization of sequence values with the maximum existing IDs in the target database, and comprehensive post-migration validation. This process ensures that new records created after the migration do not collide with existing data, maintaining referential integrity and operational continuity. The primary risks to control include silent data overwrites, failed transactions due to unique constraint violations, and reporting discrepancies caused by missing or duplicated records. By treating sequence management as a first-class component of the migration plan, organizations can significantly reduce the likelihood of post-go-live incidents and ensure a stable transition to the new ERP environment.

Understanding Odoo Sequence Mechanics

Odoo relies on PostgreSQL sequences to generate unique identifiers for records across various modules, including sales orders, invoices, and inventory moves. These sequences are typically managed by the ORM (Object-Relational Mapping) layer, which automatically increments the sequence value when a new record is created. However, during a database migration or version upgrade, the sequence state may not automatically align with the maximum ID present in the migrated data. If the sequence value is lower than the highest existing ID, the next record creation will attempt to use an ID that already exists, triggering a unique constraint violation. This is a common source of failure in Odoo migrations, particularly when data is imported from external sources or when custom modules manipulate IDs directly.

Sequence Types in Odoo

Odoo uses two primary types of sequences: standard PostgreSQL sequences and Odoo-specific sequence models. Standard sequences are used for the primary key (id) of most models, while Odoo-specific sequences are used for human-readable reference numbers, such as invoice numbers or sales order references. Both types require careful management during migration. Standard sequences must be synchronized with the maximum ID in the table, while Odoo-specific sequences must be synchronized with the maximum reference number in use. Failure to address either type can lead to functional issues, ranging from application errors to duplicate reference numbers in financial documents.

Pre-Migration Audit and Assessment

The first step in managing sequence numbers is a comprehensive audit of the source database. This involves identifying all tables with auto-incrementing primary keys and all Odoo sequence models. For each table, determine the current sequence value and the maximum ID present in the data. For Odoo sequence models, determine the current next value and the maximum reference number in use. This audit should be performed in a staging environment that mirrors the production database as closely as possible. The results of this audit will inform the migration strategy and help identify potential conflicts before they occur.

ComponentAudit ItemAction RequiredResponsible Role
PostgreSQL SequencesCurrent sequence value vs. max IDSynchronize sequence to max ID + 1Database Administrator
Odoo Sequence ModelsCurrent next value vs. max referenceUpdate sequence next valueERP Consultant
Custom ModulesDirect ID manipulationReview code for hardcoded IDsDevelopment Team
External IntegrationsID mapping logicVerify ID transformation rulesIntegration Specialist

Technical Execution: Synchronizing Sequences

Once the audit is complete, the next step is to synchronize the sequences in the target database. For PostgreSQL sequences, this can be done using the setval function, which sets the sequence value to the maximum ID in the table plus one. For Odoo sequence models, this can be done by updating the next value field in the ir_sequence table. It is important to perform this synchronization after the data migration is complete but before the application is restarted. This ensures that the sequences are aligned with the migrated data and that new records created after the migration will not conflict with existing data.

Handling Custom Modules

Custom modules may introduce additional complexity to sequence management. Some custom modules may manipulate IDs directly, bypassing the ORM, or may use custom sequence logic. These modules must be reviewed and tested to ensure that they do not interfere with the sequence synchronization process. If a custom module uses hardcoded IDs or assumes a specific sequence range, it may need to be modified to accommodate the new sequence values. This review should be part of the custom module compatibility testing process and should be documented in the migration plan.

Validation and Testing

After synchronizing the sequences, the next step is to validate the migration. This involves creating test records in the target database and verifying that they receive unique IDs and reference numbers. It is also important to test the integration points to ensure that external systems can correctly map and transform IDs. The validation process should include both automated tests and manual testing by key users. Any issues identified during validation should be documented and resolved before proceeding to the production migration.

  • Create test records for all major models and verify unique IDs.
  • Test integration points to ensure correct ID mapping.
  • Verify that Odoo sequence models generate unique reference numbers.
  • Run automated regression tests to detect any sequence-related errors.
  • Document all test results and resolve any issues before cutover.

Cutover and Deployment

The cutover phase is the final step in the migration process. It involves stopping the source system, performing the final data migration, synchronizing the sequences, and starting the target system. The cutover plan should include detailed runbooks, go/no-go criteria, and rollback procedures. The go/no-go decision should be based on the results of the validation testing and the status of any outstanding issues. If the go/no-go criteria are not met, the migration should be rolled back to the source system to avoid data loss or corruption.

Rollback Strategy

A robust rollback strategy is essential for managing the risks associated with Odoo database migrations. The rollback plan should include a verified backup of the source database, a tested restore procedure, and a clear communication plan for stakeholders. The rollback should be triggered if any critical issues are identified during the cutover or post-migration validation. It is important to test the rollback procedure in a staging environment before the production migration to ensure that it can be executed quickly and effectively.

Post-Migration Stabilization

After the migration is complete, the focus shifts to post-migration stabilization. This involves monitoring the system for any sequence-related errors, verifying that data integrity is maintained, and addressing any issues that arise. The monitoring process should include automated alerts for unique constraint violations and sequence errors. Any issues identified during the stabilization phase should be documented and resolved in a timely manner. The stabilization phase should continue until the system is operating normally and all stakeholders are satisfied with the migration outcome.

  • Monitor system logs for sequence-related errors.
  • Verify data integrity through regular reconciliation checks.
  • Address any issues identified during the stabilization phase.
  • Document lessons learned and update the migration playbook.
  • Transition to normal operations and support processes.

Risk Management and Mitigation

Managing sequence numbers and ID conflicts is a critical aspect of Odoo database migrations. By following a structured approach that includes pre-migration audit, technical execution, validation, cutover, and post-migration stabilization, organizations can significantly reduce the risks associated with the migration process. It is important to involve all relevant stakeholders, including database administrators, ERP consultants, development teams, and integration specialists, in the migration planning and execution process. By treating sequence management as a first-class component of the migration plan, organizations can ensure a stable and successful transition to the new ERP environment.

Conclusion

In conclusion, managing sequence numbers and ID conflicts is essential for a successful Odoo database migration. By following the steps outlined in this guide, organizations can prevent data corruption, broken foreign key relationships, and application errors. The key to success is a rigorous pre-migration audit, a controlled synchronization of sequence values, and comprehensive post-migration validation. By treating sequence management as a critical component of the migration plan, organizations can ensure a stable and successful transition to the new ERP environment, maintaining operational continuity and data integrity throughout the process.

Written by
SysGenPro Editorial

SysGenPro Editorial

Platform & solutions team

Practical guidance on ERP, AI automation, cloud deployment and enterprise transformation from the SysGenPro team.

Share this article

Frequently asked questions

Common questions on this topic. Talk to our team for anything specific to your business.

01What happens if sequence numbers are not updated during Odoo migration?

If sequence numbers are not updated, new records may attempt to use IDs that already exist, causing unique constraint violations and application errors. This can lead to data loss, failed transactions, and reporting discrepancies.

02How do I check the current sequence value in Odoo?

You can check the current sequence value by querying the PostgreSQL database using the last_value column in the sequence table. For Odoo-specific sequences, you can check the next value field in the ir_sequence table.

03Can I manually reset sequences in Odoo after an upgrade?

Yes, you can manually reset sequences using the setval function in PostgreSQL for standard sequences and by updating the next value field in the ir_sequence table for Odoo-specific sequences. This should be done carefully and tested in a staging environment first.

04What are the risks of ignoring ID conflicts in ERP migration?

Ignoring ID conflicts can lead to data corruption, broken foreign key relationships, application errors, and reporting discrepancies. It can also cause integration failures and require significant time and resources to resolve after the migration.

05How does Odoo handle auto-incrementing IDs during data import?

Odoo typically uses the ORM to manage auto-incrementing IDs during data import. However, if data is imported directly into the database or if custom modules manipulate IDs, the sequence values may not be synchronized, leading to potential conflicts.

06Is it safe to migrate Odoo databases across different PostgreSQL versions?

Migrating Odoo databases across different PostgreSQL versions requires careful planning and testing. Compatibility and support must be verified against the vendor's official documentation for the exact source and target versions. It is recommended to perform a full backup and test the migration in a staging environment before proceeding to production.

Continue learning
View all articles
Explore the platform

Where to go next

Browse the knowledge hub

See how SysGenPro fits your business

Discuss your workflows, modules and deployment options with our team.

Back to resources