Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mahaguru24's avatar

PDOException: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: orders.reconciled

I am updating a legacy project from laravel9 to laravel 11.

After updating laravel 10 to 11 i started getting below error in test cases.

Caused by PDOException: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: orders.reconciled

I have a schema dump for the sqlite.

Here is a statement in the file CREATE TABLE orders (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, cts DATETIME DEFAULT NULL, type_id INTEGER DEFAULT NULL, status_id INTEGER DEFAULT NULL, email VARCHAR(128) DEFAULT NULL COLLATE "BINARY", address VARCHAR(128) DEFAULT NULL COLLATE "BINARY", currency_value DOUBLE PRECISION DEFAULT NULL, commis_rate DOUBLE PRECISION DEFAULT NULL, cash_status_id INTEGER DEFAULT NULL, cash_uts DATETIME DEFAULT NULL, exchange_id INTEGER DEFAULT NULL, coin_value DOUBLE PRECISION DEFAULT NULL, coin_status_id INTEGER DEFAULT NULL, coin_uts DATETIME DEFAULT NULL, valid_minutes INTEGER DEFAULT NULL, commis_value DOUBLE PRECISION DEFAULT NULL, cash_exchange_id INTEGER DEFAULT NULL, cash_bank_trans_id INTEGER DEFAULT NULL, bc_confirms INTEGER DEFAULT NULL, prior_order_count INTEGER DEFAULT NULL, btcgst INTEGER DEFAULT NULL, op_id INTEGER DEFAULT -1 NOT NULL, currency VARCHAR(255) DEFAULT NULL COLLATE "BINARY", customer_id INTEGER DEFAULT NULL, user_id INTEGER DEFAULT NULL, msisdn VARCHAR(255) DEFAULT NULL COLLATE "BINARY", fulfilment_id INTEGER DEFAULT NULL, order_key VARCHAR(255) DEFAULT NULL COLLATE "BINARY", ip VARCHAR(128) DEFAULT NULL COLLATE "BINARY", pre_fraud_status_id INTEGER DEFAULT NULL, psp_fees DOUBLE PRECISION DEFAULT NULL, tags VARCHAR(255) DEFAULT NULL COLLATE "BINARY", bc_txid VARCHAR(255) DEFAULT NULL COLLATE "BINARY", kyc_collect VARCHAR(255) DEFAULT NULL COLLATE "BINARY", kyc_verify VARCHAR(255) DEFAULT NULL COLLATE "BINARY", coin VARCHAR(10) DEFAULT NULL COLLATE "BINARY", merch_id INTEGER DEFAULT NULL, merch_commis_rate DOUBLE PRECISION DEFAULT '0', merch_commis_value DOUBLE PRECISION DEFAULT '0', merch_commis_disc DOUBLE PRECISION DEFAULT '0', reconciled INTEGER DEFAULT 0 NOT NULL, comment_categories INTEGER DEFAULT NULL, email_sent VARCHAR(255) DEFAULT NULL COLLATE "BINARY", merch_ref VARCHAR(255) DEFAULT NULL COLLATE "BINARY", order_type_id INTEGER DEFAULT 1 NOT NULL, payment_type_id INTEGER DEFAULT NULL, psp_id INTEGER DEFAULT NULL, accounted INTEGER DEFAULT 0 NOT NULL, uts DATETIME DEFAULT NULL, pre_fulfilment_id INTEGER DEFAULT NULL, expire_from DATETIME DEFAULT NULL, payment_status_id INTEGER DEFAULT 0 NOT NULL, api_key VARCHAR(255) DEFAULT NULL COLLATE "BINARY", flags INTEGER DEFAULT 0 NOT NULL, commis_value_tax DOUBLE PRECISION DEFAULT NULL, psp_fees_tax DOUBLE PRECISION DEFAULT NULL, currency_cost DOUBLE PRECISION DEFAULT NULL, customer_payment_detail_id INTEGER UNSIGNED DEFAULT NULL, address_tag VARCHAR(255) DEFAULT NULL COLLATE "BINARY", pre_fulfilment_exchange_id INTEGER DEFAULT NULL, kyc_tier_id INTEGER DEFAULT NULL, currency_value_ref DOUBLE PRECISION DEFAULT NULL, currency_ref VARCHAR(255) DEFAULT NULL COLLATE "BINARY", spread_rate DOUBLE PRECISION DEFAULT NULL, spread_value DOUBLE PRECISION DEFAULT NULL, merch_spread_rate DOUBLE PRECISION DEFAULT NULL, merch_spread_value DOUBLE PRECISION DEFAULT NULL, coin_payment_detail_id INTEGER DEFAULT NULL, ops_status_id INTEGER DEFAULT NULL, flag_id INTEGER DEFAULT 0 NOT NULL, recovery_fee_rate DOUBLE PRECISION DEFAULT NULL, recovery_fee_value DOUBLE PRECISION DEFAULT NULL, accounted_sales_ts DATE DEFAULT NULL, blockchain_id INTEGER DEFAULT NULL, "network_fee_incl_tax" float, "network_fee_tax" float);

If I run it separately, it assigns a default value for reconciled as 0 however if its run inside test case then its not assigning the default value as 0.

Any idea what might fix it?

0 likes
2 replies
LaryAI's avatar
Level 58

It seems like the issue you're encountering is related to the reconciled column in your orders table. The error message indicates that the NOT NULL constraint is being violated, which means that a NULL value is being attempted to be inserted into the reconciled column, even though the column is defined with a default value of 0.

Here are a few steps you can take to troubleshoot and resolve this issue:

  1. Check Your Model Factory or Seeder: If you're using a model factory or a seeder to create test data, ensure that it's not setting the reconciled column to NULL. If it is, you should either remove this line or set a default value of 0.

  2. Check Your Test Code: Review the test code where the orders table is being populated. Make sure that you're not explicitly setting the reconciled column to NULL when creating an order.

  3. Database Migration: If you have a migration file for the orders table, ensure that the reconciled column is set to have a default value of 0. The migration should look something like this:

Schema::create('orders', function (Blueprint $table) {
    // ... other columns ...
    $table->integer('reconciled')->default(0)->notNull();
    // ... other columns ...
});
  1. Database Configuration: Since you're using SQLite, make sure that your database configuration is correct for testing. SQLite behaves slightly differently than other databases, and sometimes this can cause issues with default values.

  2. Database Refresh: If you're running tests, you might want to refresh your database before each test to ensure that the schema is applied correctly. You can do this by using the RefreshDatabase trait in your test classes.

  3. Explicitly Set Default Value in Tests: If none of the above solutions work, you can explicitly set the default value in your tests when creating an order:

$order = Order::create([
    // ... other attributes ...
    'reconciled' => 0,
]);
  1. Check Laravel Version Upgrade Guide: Since you've upgraded from Laravel 10 to 11, check the upgrade guide for any changes in database behavior or testing that might affect default values.

If after trying these steps the issue persists, it might be helpful to provide more context or code snippets from your test cases or model factories that are involved in the creation of the orders records. This will help in pinpointing the exact cause of the issue.

1 like
mahaguru24's avatar

The schema dump was actual SQLite dump from the DB, so regenerated the dump using schema:dump command then tests started working correctly

Please or to participate in this conversation.