When you want to add a string type column with a limited length with the `rails generate migration` command

You can do something like string {n}.

$ rails g migration AddNameToUsers name:string{30}

The generated migration file will be as follows

class AddNameToUsers < ActiveRecord::Migration[6.0]
  def change
    add_column :users, :name, :string, limit: 30
  end
end

You can also use uniq and index, but note that I forget only limit for some reason.

reference

Recommended Posts

When you want to add a string type column with a limited length with the `rails generate migration` command
[Rails] How to create a table, add a column, and change the column type
I want to add a reference type column later
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
I want to add a browsing function with ruby on rails
[Rails] I want to add data to Params when transitioning with link_to
[Swift] When you want to know if the number of characters in a String matches a certain number ...
When you want to check whether the contents of a property can be converted to a specific type
A memo when you want to clear the time part of the calendar
When you want Rails to disable a session for a specific controller only
What to do when you want to delete a migration file that is "NO FILE"
When you want to use the method outside
[Rails] When transitioning to a page with link_to, move to the specified location on the page
When importing CSV with Rails, it was really easy to use the nkf command
How to manually generate a JWT with Rails Knock
I want to add a delete function to the comment function
[Ruby + Rails] When you want to register in Mailchimp's mail list together with user registration
When you want to change the wording to be displayed when making a select box from enum
I want to return a type different from the input element with Java8 StreamAPI reduce ()
[Rails] What to do when the view collapses when a message is displayed with the errors method
How to automatically generate ER diagram when migrating with Rails6
[Rails] Processing after adding a column to the devise table
How to write a migration from Rails datetime type to date type
What to do when you launch an application with rails
[Ruby on Rails] Add a column with a foreign key constraint
I want to create a form to select the [Rails] category
When you want to explicitly write OR or AND with ransack
When you want to change the MySQL password of docker-compose
docker-compose.yml when you want to keep mysql running with docker
lombok.config when you want to pass @Qualifier to @RequiredArgsConstructor with lombok
I want to pass the startup command to postgres with docker-compose.
What to do if you can't use the rails command
A memorandum when you want to see the data acquired by Jena & SPARQL for each variable.
When a beginner makes a personal app with rails, the procedure to bring it to the starting point anyway.
[Rails] Add column to devise
A trick when you want to insert a lot of line breaks and tabs when substituting a character string
[PostgreSQL] If you want to delete the Rails app, delete the database first!
When you want to ZIP download the image data saved locally
I got a warning message with the rails _6.0.3_ new hello_myapp command
Why you should add the Override annotation when overriding a method
[Docker] Magic command when you want to wipe out none image
When you have introduced devise but want to add more columns
[For beginners] I want to automatically enter pre-registered data in the input form with a selection command.
The first thing to do when you want to be happy with Heroku on GitHub with Eclipse in Java
What to do if Operation not permitted is displayed when you execute a command in the terminal
[For beginners] When you want to say that the JVM (-D) option does not work with the java -jar command, or that the library is buggy.
[Rails] What to do if you get an error saying "Could not find a JavaScript runtime." When executing the rails s command on Catalina
[Rails] How to log in with a name by adding a devise name column
Summary of means when you want to communicate with HTTP on Android
If you want to make a zip file with Ruby, it's rubyzip.
I want to introduce the committee with Rails without getting too dirty
How to reference a column when overriding the column name method in ActiveRecord
What to do if you get an "A server is already running." Error when you try to start the rails server
[Rails] [Parent-child relationship] I want to register the foreign key in the child with nil when the parent is deleted.
[Ruby] I want to make an array from a character string with the split method. And vice versa.