Skip to content

SchemaMismatchError

class

Defined in src/ralph/errors.cr:314

Raised when model columns don't match the ResultSet columns during hydration

This error catches mismatches between what a model expects and what the database actually returns. Common causes: - Model is missing columns that exist in the database - Model has extra columns not in the database - Column order mismatch (when using SELECT * or wrong column order) - Schema drift after database migrations

Example

# When loading a Supply record with mismatched schema:
Supply.find(id)
# => Ralph::SchemaMismatchError: ResultSet mismatch for Supply (table: supplies)
#
#    Expected 16 columns, got 18 from database
#
#    Missing in model (add these columns):
#      - catalog_supply_id
#      - tenant_catalog_supply_id
#
#    First mismatch at index 0:
#      Expected: id
#      Got: created_at
#
#    Hint: Run `ralph db:pull` to regenerate your model from the database schema,
#    or manually add the missing columns to your model definition.

Constructors

.new(model_name : String, table_name : String, expected_columns : Array(String), actual_columns : Array(String))

View source


Instance Methods

#summary

View source

Get a summary suitable for logging