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

  • SEARCH
  • Home
  • 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 8826981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:16:28+00:00 2026-06-14T07:16:28+00:00

I have a user table that belongs_to :user_category, and user_category has_many :users. I’m trying

  • 0

I have a user table that “belongs_to :user_category”, and user_category “has_many :users”. I’m trying to set the type to “:references” like so…

class AddUserCategoryToUsers < ActiveRecord::Migration
  def change
    add_column :users, :user_category, :references, :default => 1
  end
end

But it doesn’t appear to be working:

==  CreateUsers: migrating ====================================================
-- create_table(:users)
   -> 0.0114s
==  CreateUsers: migrated (0.0115s) ===========================================

==  CreateUserCategories: migrating ===========================================
-- create_table(:user_categories)
   -> 0.0118s
==  CreateUserCategories: migrated (0.0119s) ==================================

==  AddUserCategoryToUsers: migrating =========================================
-- add_column(:users, :user_category, :references, {:default=>1})
rake aborted!
An error has occurred, all later migrations canceled:

Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'references DEFAULT 1' at line 1: ALTER TABLE `users` ADD `user_category` references DEFAULT 1

Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Here’s the full trace:

-- add_column(:users, :user_category, :references, {:default=>1})
rake aborted!
An error has occurred, all later migrations canceled:

Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'references DEFAULT 1' at line 1: ALTER TABLE `users` ADD `user_category` references DEFAULT 1
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `query'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `block in execute'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `execute'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in `execute'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:461:in `add_column'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:466:in `block in method_missing'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:438:in `block in say_with_time'
/Users/jakebuob/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/benchmark.rb:280:in `measure'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:438:in `say_with_time'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:458:in `method_missing'
/Users/jakebuob/Sites/pears/db/migrate/20121114033751_add_user_category_to_users.rb:3:in `change'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:407:in `block (2 levels) in migrate'
/Users/jakebuob/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/benchmark.rb:280:in `measure'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:407:in `block in migrate'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:123:in `with_connection'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:389:in `migrate'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:528:in `migrate'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:777:in `call'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:777:in `ddl_transaction'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:719:in `block in migrate'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:700:in `each'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:700:in `migrate'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:570:in `up'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/migration.rb:551:in `migrate'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:153:in `block (2 levels) in <top (required)>'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/jakebuob/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/bin/rake:19:in `load'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286@global/bin/rake:19:in `<main>'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/bin/ruby_noexec_wrapper:14:in `eval'
/Users/jakebuob/.rvm/gems/ruby-1.9.3-p286/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate
  • 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-06-14T07:16:29+00:00Added an answer on June 14, 2026 at 7:16 am

    The :references type doesn’t exist. You need to create the real column.

    class AddUserCategoryToUsers < ActiveRecord::Migration
      def change
        add_column :users, :user_category_id, :integer, :default => 1
      end
    end
    

    It’s also a good idea to create an index.

    class AddUserCategoryToUsers < ActiveRecord::Migration
      def change
        add_column :users, :user_category_id, :integer, :default => 1
        add_index :users, :user_category_id
      end
    end
    

    The .references method exists only as part of the table definition (here’s an example)

    class AddUserCategoryToUsers < ActiveRecord::Migration
      def change
        change_table :users do |t|
          t.references :user_category, :default => 1
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user table 'users' that has fields like: id first_name last_name ...
I have a User table that has all of their avatars saved in an
Currently I have a User table that has a toys_owned column that is an
I have frequent updates to a user table that simply sets the last seen
I have a table (user) that contains user information. I have another table (userview)
I have an user defined table function in SQL Server that aggregate data from
I have a table that stores user information. The table has a userid (identity)
I have a table that has account numbers in (account_num) and user profiles (profile_id).
I have a table that includes 27 DropDownLists for user input. My table has
I have a User and Group model. User has_many Groups and Group belongs_to User

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.