Rails : migration for creating a fixed-length char(12) column

If Rails doesn’t understand the column type, it’ll pass it straight through to the database. So if you want a char instead of varchar, just replace: t.column :token, :string With: t.column :token, “char(12)” Of course, this may or may not make your migrations non-portable to another database. (credit to http://laurelfan.com/2010/1/26/special-mysql-types-in-rails-migrations)

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