{"record":{"id":"4557260cb17fb05a","repo":"firefly-iii/firefly-iii","slug":"300006","errorCode":"300006","errorMessage":"300006: Journal #%d, transaction #%d has no destination account.","messagePattern":"300006: Journal #(.+?), transaction #(.+?) has no destination account\\.","errorType":"console","errorClass":"FireflyException","httpStatus":null,"severity":"error","filePath":"app/Console/Commands/Correction/CorrectsTransactionTypes.php","lineNumber":136,"sourceCode":"     * @throws FireflyException\n     */\n    private function getDestinationAccount(TransactionJournal $journal): Account\n    {\n        $collection  = $journal->transactions->filter(static fn (Transaction $transaction): bool => $transaction->amount > 0);\n        if (0 === $collection->count()) {\n            throw new FireflyException(sprintf('300004: Journal #%d has no destination transaction.', $journal->id));\n        }\n        if (1 !== $collection->count()) {\n            throw new FireflyException(sprintf('300005: Journal #%d has multiple destination transactions.', $journal->id));\n        }\n\n        /** @var Transaction $transaction */\n        $transaction = $collection->first();\n\n        /** @var null|Account $account */\n        $account     = $transaction->account;\n        if (null === $account) {\n            throw new FireflyException(sprintf('300006: Journal #%d, transaction #%d has no destination account.', $journal->id, $transaction->id));\n        }\n\n        return $account;\n    }\n\n    /**\n     * @throws FireflyException\n     */\n    private function getSourceAccount(TransactionJournal $journal): Account\n    {\n        $collection  = $journal->transactions->filter(static fn (Transaction $transaction): bool => $transaction->amount < 0);\n        if (0 === $collection->count()) {\n            throw new FireflyException(sprintf('300001: Journal #%d has no source transaction.', $journal->id));\n        }\n        if (1 !== $collection->count()) {\n            throw new FireflyException(sprintf('300002: Journal #%d has multiple source transactions.', $journal->id));\n        }\n","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/firefly-iii/firefly-iii/blob/fd8791d08d4d9e6467519a78048cd038e26b8878/app/Console/Commands/Correction/CorrectsTransactionTypes.php#L118-L154","documentation":"Thrown by correction:transaction-types when the destination transaction row exists but its ->account relation resolves to null. This means transactions.account_id points to a row that no longer exists in the accounts table (dangling foreign key), so code 300006 is raised. Firefly III relies on the relation being non-null to infer journal types.","triggerScenarios":"Running firefly-iii:correct-database or correction:transaction-types where a transaction row references a deleted or never-created account. Typical after account deletion without cascade, partial restores, or direct SQL truncation of accounts.","commonSituations":"Databases where accounts were deleted with foreign key checks disabled, or where the accounts table was partially restored. Imports that wrote account_id values computed against a different database. Schema drift after switching between MySQL/PostgreSQL/SQLite copies.","solutions":["Find dangling references: SELECT t.id, t.account_id FROM transactions t LEFT JOIN accounts a ON a.id = t.account_id WHERE a.id IS NULL.","Back up, then either re-point each transaction to a valid account_id or delete the orphaned transaction rows (correction:orphaned-transactions does the latter).","Verify foreign key constraints exist and are enforced on your database engine (InnoDB, not MyISAM; PRAGMA foreign_keys for SQLite).","Re-run the correction command to confirm a clean pass."],"exampleFix":"php artisan correction:orphaned-transactions\n# removes transaction rows whose account no longer exists","handlingStrategy":"try-catch","validationCode":"-- pre-flight: transactions pointing at missing accounts\nSELECT t.id FROM transactions t\nLEFT JOIN accounts a ON a.id = t.account_id\nWHERE a.id IS NULL;","typeGuard":null,"tryCatchPattern":"try {\n    $this->artisan('correction:transaction-types');\n} catch (FireflyException $e) {\n    if (preg_match('/300006: Journal #(\\d+), transaction #(\\d+)/', $e->getMessage(), $m)) {\n        // re-point transaction (int)$m[2] to a valid account_id or remove it, re-run\n    }\n}","preventionTips":["Never truncate or prune the accounts table by hand.","Use InnoDB (or enforce FKs) so account deletion cascades or fails loudly.","Run correction:orphaned-transactions periodically as routine hygiene."],"tags":["console","correction-command","data-integrity","dangling-foreign-key","database","error-code"],"backgroundTag":"dangling-foreign-key","analyzedSha":"fd8791d08d4d9e6467519a78048cd038e26b8878","analyzedAt":"2026-08-17T02:14:53.848Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}