How to change part of a schema in Ruby on Rails?

I tried to change the schema.rb line (t.string should become t.text), but I cannot change it directly through the file, because when I use rake db: migrate, the changes return to the previous state.

How can I change this line?

EDIT: If I didn't understand anything, I have to edit the file inside db / migrate. In my case, this is 2010110801532_create_posts.rb, where exactly will I have to place the change_column part?

This is my 2010110801532_create_posts.rb

class CreatePosts < ActiveRecord::Migration
  def self.up
    create_table :posts do |t|
      t.string :nome
      t.string :titolo
      t.text :contenuto

      t.timestamps
    end
  end

  def self.down
    drop_table :posts
  end
end
+3
source share
3 answers

Step by step:

First create a new migration:

./script/generate migration change_string_to_text

In the generated migration file nnnnnnnnnnn_change_string_to_text.rbyou need to add the line:

change_column :table_name, :column_name, :text

rake migrate, .

+4

, . , .

change_column :table_name, :column_name, :text
+3

The schema.rb file is automatically generated by rake, so any changes you make will be overwritten. As Match noted, migration is a path starting with:

./script/generate migration change_string_to_text
0
source

Source: https://habr.com/ru/post/1773733/


All Articles