Skip to content

Data too long for column ticker - Schema alignment fix

Ticket #199: Data too long for column 'ticker'
Type: Debugging / Bug Fix / Data Integrity
Affected Component: code_source_simule/flask_app.py, code_source_simule/pipeline.py, tests/test_pipeline.py


1. Context and Symptoms

Starting April 14, 2026, the daily import failed with:

Data too long for column 'ticker' at row N

No data imported until resolved.


2. Investigation

SSH diagnosis revealed the root cause:

SHOW COLUMNS FROM titres WHERE Field = 'ticker'
# Result: varchar(10)

Finding: Production database has VARCHAR(10) for ticker, but code_source_simule/flask_app.py defines db.String(20). The schema mismatch prevented insertion of modern tickers (e.g., BRK.B, BF.A).


3. Root Causes

# Cause Status
1 ORM model db.String(20) misaligned with VARCHAR(10) in production Fixed
2 No tests validating schema/ORM consistency Fixed

4. Solutions

4.1 - Increase ticker field to VARCHAR(255) in ORM

# flask_app.py
ticker = db.Column(db.String(255), unique=True, nullable=False)

Aligns with create_tables_if_not_exist() which creates VARCHAR(255) for new installations.

4.2 - Add TDD Tests

New test class TestTickerLengthValidation: - tc-pipe-ticker01: Insert ticker with reasonable length - tc-pipe-ticker02: Insert ticker at maximum length (255 chars)


5. Verification

  • New tests: 2 passing
  • Regression tests: 40/40 passing, no breakage
  • Coverage: Updated and stable

6. Lessons

  1. ORM/Schema consistency is critical. Any mismatch between SQLAlchemy models and SQL schemas must be caught early by automated tests.
  2. Schema boundaries must be tested. Tests like TestTickerLengthValidation prevent "Data too long" errors in production.
  3. Documentation must align with code. Chapter 2 was updated to note the VARCHAR(255) ticker field and the schema consistency rule.