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 7595519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:41:29+00:00 2026-05-30T21:41:29+00:00

Hi I created a table for a wiki application that I was doing. It

  • 0

Hi I created a table for a wiki application that I was doing. It was pretty simple in the beginning I had a Questions table and an Answers table. I now want to add users to it. So for that I created a users table and the whole signup thing is ready. The wiki part is working and the users part is working but I am having trouble to merge them together.

I first created a Questions as a scaffold as follows:

   rails g scaffold Question title:string body:string 

Then Answers as follows:

   rails g scaffold Answer question_id:integer content:string

I then tried to add the users_id column after creating the Users table:

   rails generate migration add_users_id_to_questions user_id:integer

I then tried to index the user_id column by adding the following line in the migration file:

   class AddUserIdToQuestions < ActiveRecord::Migration
      def change
        add_column :questions, :user_id, :integer
      end
        add_index :questions, :user_id
   end

I do rake:db migrate but it doesnt show the change after I run migration. Is there any other way I can index user_id other than by adding a column to the migration file. I even ran rake db:rollback so the addition of user_id column is gone but when I make the change and run rake db:migrate it gives me an error user_id doesnt exist. It would be greatly appreciated if you could help me how to create the index. I running Rails 3, SQLite as my DB.
Thank you.

  • 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-30T21:41:30+00:00Added an answer on May 30, 2026 at 9:41 pm

    Rollback and then re-run the migration with add_index inside the change block.

    class AddUserIdToQuestions < ActiveRecord::Migration
      def change
        add_column :questions, :user_id, :integer
        add_index :questions, :user_id
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a table in my application, I want to select (change background
i already created a table for comments but i want to add the feature
I've created a table in Microsoft Sql CE that I'm using to hold some
We have created a table with a trigger that updates a ModifiedDate field in
I want to create a simple visualization tool that would allow to represent my
I'm trying to create a migration for a simple table that is just used
I want to get the last created table name from a MySQL database using
i have created table using Sqlite3.and also inserted record in that table.its running successfully.but
Let's say I have a dynamically-created table that is filled with data from a
I have a dynamically created table which in the last <td> there is a

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.