Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 872431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:47:00+00:00 2026-05-15T10:47:00+00:00

im trying to understand the process of creating tables in ruby-on-rails 3. i have

  • 0

im trying to understand the process of creating tables in ruby-on-rails 3.

i have read about migrations. so i am supposed to create tables by editing in the files in:

Database Migrations/migrate/20100611214419_create_posts
Database Migrations/migrate/20100611214419_create_categories

but they were generated by:

rails generate model Post name:string description:text
rails generate model Category name:string description:text

does this mean i have to use “rails generate model” command everytime i want to create a table?

what if i create a migration file but want to add columns. do i create another migration file for adding those or do i edit the existing migration file directly? the guide told me to add a new one, but here is the part i dont understand. why would i add a new one? cause then the new state will be dependent of 2 migration files.

and how do i add a new migration file for updating then? what is the command? and if i have to drop columns or edit them. how do it do that?

rails generate model Post name:string description:text

cause the above command just add columns.

and if i don’t use the commands, how do i create migration files?

in symfony i just edit a schema.yml file directly, there are no migration files with versioning and so on.

and i think in django you just create the models and it will create the database tables.

im new to RoR and want to get the picture of creating tables.

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:47:00+00:00Added an answer on May 15, 2026 at 10:47 am

    If you want to update a table you have to create a new migration file because each migrations is executed only once on the database. So if you already have a posts table then after modifying the create_posts migration you won’t be able to run it again.

    You can rollback migrations and then run them again. That would solve the problem but it would also destroy the table and the data that it might hold. This isn’t a problem if you just created the migration and then noticed that you missed one column. Then you can just add the column to the migration, rollback and migrate. But you don’t want to do that on a production database!

    To create a new migration you just run:

    rails generate migration migration_name
    

    If you call your migration add_*_to_table then you can also pass the same arguments as in generate model:

    rails generate migration add_something_to_posts something:boolean
    

    This will automatically generate this migration:

    class AddSomethingToPosts < ActiveRecord::Migration
      def self.up
        add_column :posts, :something, :boolean
      end
    
      def self.down
        remove_column :posts, :something
      end
    end
    

    This will work with remove_*_from_table too:

    rails generate migration remove_something_from_posts something:boolean
    

    The migration will be:

    class RemoveSomethingFromPosts < ActiveRecord::Migration
      def self.up
        remove_column :posts, :something
      end
    
      def self.down
        add_column :posts, :something, :boolean
      end
    end
    

    Here are some more methods that you can use in your migrations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand the initialization process for Rails 3 plugins. I have
I am trying understand ViewModels deeper and I have read many articles and blogs
I'm trying to understand the python compiler/interpreter process more clearly. Unfortunately, I have not
I am in the process of trying to understand caching options in Rails (and
I am trying to understand the process of dynamic linking, in detail. For the
I'm trying to understand the signing process of .NET applications. I'm working with Visual
I am trying to fully understand the process pro writing code in some language
I am trying to understand what the 'Attach to process' is useful for in
Trying to understand Ruby a bit better, I ran into this code surfing the
Trying to understand this binding process of the WPF. See the code at the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.