[RAILS] (Solution) Mysql2 :: Error: Field'Column name' doesn't have a default value

In implementing the user management function, when devise was introduced and new registration was attempted, a title error occurred. The solution and cause are described below.

Solutions

Set the strong parameters of devise. A code example is shown below.

application_controller


class ApplicationController < ActionController::Base
  before_action :configure_permitted_parameters, if: :devise_controller?

  private
  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:nickname, :first_name,(Multiple column names)])
  end
end

Cause of the error

The content of the error statement is "The column name specified in mysql is not set with the default value". The only columns set by default in devise are email and password. Therefore, even if you try to save other columns through devise, you cannot save the user information.

Why it is solved

The above code allows columns other than email and password to be saved as user information through devise. Therefore, columns that are not set by default can be saved and the error is resolved.

Recommended Posts

(Solution) Mysql2 :: Error: Field'Column name' doesn't have a default value
(Solution) Mysql2 :: Error: Table'users' already exists
Apparently CentOS doesn't have a terminal shortcut
Multiple migrations have the name Error resolution
Dealing with Mysql2 :: Error: Incorrect string value error