Skip to Content
Menu
This question has been flagged

I was testing all sorts of things in our actual database instead of a test database and want to reset everything back to "brand new" so we don't have all the test info mixed in with real purchases, orders, transfers (receipts, deliveries and internal)

I realize I should have been using a test database or test environment but I did not know how to do that since I just started using Odoo. We are finally set up and now I need to clear all previous data

Avatar
Discard
Best Answer

Hello Adam,

Resetting an Odoo database to remove all test transactions while keeping the basic configuration intact can indeed be achieved by running SQL queries, but this should be done carefully. 

Here's a comprehensive guide to help you safely reset your database:

Odoo stores transactional data in several tables, such as:

  • Sales Orders: sale_order and sale_order_line
  • Purchases: purchase_order and purchase_order_line
  • Inventory Transactions: stock_picking, stock_move, stock_quant, etc.
  • Accounting: account_move, account_move_line, account_invoice, etc.
You need to delete related records in the correct order to maintain data integrity. Odoo uses a lot of foreign key constraints, so you may need to cascade deletions.

Here's a general SQL script to reset transactional data:

DELETE FROM sale_order_line; DELETE FROM sale_order; -- Clear Purchase Orders DELETE FROM purchase_order_line; DELETE FROM purchase_order; -- Clear Inventory Transactions DELETE FROM stock_move_line; DELETE FROM stock_move; DELETE FROM stock_picking; -- Clear Stock Quant DELETE FROM stock_quant; -- Clear Accounting Entries DELETE FROM account_move_line; DELETE FROM account_move; -- Clear CRM Data (if applicable) DELETE FROM crm_lead;

To delete specific records from Odoo's database using SQL queries, it's crucial to use appropriate WHERE clauses. This approach ensures that only the targeted data is removed, leaving other records untouched.


Example: Removing Test Records

If you want to remove only test records created by a specific user or within a specific date range, you can add these conditions to the WHERE clause:

DELETE FROM sale_order_line
WHERE order_id IN (SELECT id FROM sale_order WHERE id = 5);

DELETE FROM sale_order
WHERE id = 5;

-- Delete records created after a specific date
DELETE FROM purchase_order
WHERE create_date >= '2024-01-01';


Thanks & Regards,

CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209

Email: info@candidroot.com

Avatar
Discard
Related Posts Replies Views Activity
0
Mar 25
326
2
Feb 25
475
1
Dec 24
646
2
Feb 25
1102
2
Oct 24
11866