OptimumCredo.Check.Warning.RequiredFieldConsistency (OptimumCredo v0.5.0)
View SourceBasics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of low and works with any version of Elixir.
Explanation
A column that is null: false in the migration should be required by the changeset.
Bad
# migration: add :title, :string, null: false
schema "posts" do
field :title, :string
end
def changeset(post, attrs), do: cast(post, attrs, [:title])Good
def changeset(post, attrs) do
post |> cast(attrs, [:title]) |> validate_required([:title])
endThe check replays migrations from disk; see the module docs for its limits.
Check-Specific Parameters
Use the following parameters to configure this check:
:migrations_path
Migrations directory relative to the project root.
This parameter defaults to "priv/repo/migrations".
:ignore_fields
Columns that are set by the system and never reported.
This parameter defaults to [:id, :inserted_at, :updated_at].
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.