Skip to content

False positive for Rails/NotNullColumn when adding not null constraint to text column ? #952

Closed
@j-miyake

Description

Rails/NotNullColumn warns against adding the not null constraint to text column without the default value, however the default value can't be set for text column in MySQL. I'm not sure if this is a bug, but it made me confused. Should we fix this behavior?

C: Rails/NotNullColumn: Do not add a NOT NULL column without a default value.
    add_column :users, :bio, :text, null: false
                                    ^^^^^^^^^^^

Expected behavior

No warnings.

Actual behavior

Get a warning for Rails/NotNullColumn.

Steps to reproduce the problem

Run rubocop against to this migration code.

class AddBioToUsers < ActiveRecord::Migration[7.0]
  def change
    add_column :users, :bio, :text, null: false
  end
end

RuboCop version

$ rubocop -V
1.48.0 (using Parser 3.2.1.1, rubocop-ast 1.27.0, running on ruby 3.2.1) [aarch64-linux]
  - rubocop-performance 1.16.0
  - rubocop-rails 2.18.0
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.19.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions