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)

What is the best way to drop a table & remove a model in Rails 3?

The second method is the ideal way to handle this: your migration files are meant to represent how your database has changed over time. The older migration files will remain in your project (in case, hypothetically, you wanted to roll back to an older version), but Rails will not run them when you rake db:migrate … Read more

When I run the rake:db migrate command I get an error “Uninitialized constant CreateArticles”

Be sure that your file name and class name say the same thing(except the class name is camel cased).The contents of your migration file should look something like this, simplified them a bit too: #20090106022023_create_articles.rb class CreateArticles < ActiveRecord::Migration def self.up create_table :articles do |t| t.belongs_to :user, :category t.string :title t.text :synopsis, :limit => 1000 … Read more

Rails naming convention for join table

categories_products. Both plural. In lexical order. Quote: Unless the name of the join table is explicitly specified by using the :join_table option, Active Record creates the name by using the lexical order of the class names. So a join between customer and order models will give the default join table name of “customers_orders” because “c” … Read more

Rails Migration with adding and removing reference

Rails 4.2.1 rails g migration RemoveClientFromUsers client:references Will generate a migration similar: class RemoveClientFromUser < ActiveRecord::Migration def change remove_reference :users, :client, index: true, foreign_key: true end end In addition, one is at liberty to add another or other reference(s) by adding: add_reference :users, :model_name, index: true, foreign_key: true within the very change method. And finally … Read more