varchar Migration question for Ruby on Rails

The correct format would be t.string :note, :limit => 1000 make sure you are using a version of MySQL(or whichever database) which supports varchars longer than 256 characters. if you want to use a large text block it would be t.text :note See http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html for more information

Rails: Is it bad to have an irreversible migration?

If you are dealing with production-grade systems then yes, it is very bad. If it is your own pet project, then anything is allowed (if nothing else, it will be a learning experience 🙂 though chances are that sooner rather than later, even in a pet project, you will find yourself having put a cross … Read more

How to create a migration to remove an index only if it exists, rather than throwing an exception if it doesn’t?

You can use the index_exists? method within your migration to test whether the index you need to remove is actually there. Take a look at the documentation here: http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/index_exists%3F I’ve not tested it, but you should be able to use something like this: class AddTimestampIndexes < ActiveRecord::Migration def up remove_index :books, :created_at if index_exists?(:books, :created_at) … Read more

Removing default value from Rails Migration

Create a new migration and use change_column_default. http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/change_column_default Sets a new default value for a column: change_column_default(:suppliers, :qualification, ‘new’) change_column_default(:accounts, :authorized, 1) Setting the default to nil effectively drops the default: change_column_default(:users, :email, nil)