Note that there are some explanatory texts on larger screens.

plurals
  1. PORails creating migration to add columns to table causes error when running rake db:migrate
    text
    copied!<p>I have a model created called "users" and i created a new migration to add some columns to the users table. Now when i run rake db:migrate, I get the error below b/c it's trying to create the users table again</p> <pre><code>$ rake db:migrate == DeviseCreateUsers: migrating ============================================== -- create_table(:users) rake aborted! An error has occurred, all later migrations canceled: Mysql::Error: Table 'users' already exists: CREATE TABLE `users`..... </code></pre> <p>Why is it trying to create the table again?</p> <p>Here's the command i used to create the new migration</p> <pre><code>$ rails generate migration AddDetailsToUsers home_phone:decimal cell_phone:decimal work_phone:decimal birthday:date home_address:text work_address:text position:string company:string </code></pre> <p>The new migration looks like this:</p> <pre><code>class AddDetailsToUsers &lt; ActiveRecord::Migration def change add_column :users, :home_phone, :decimal add_column :users, :cell_phone, :decimal add_column :users, :work_phone, :decimal add_column :users, :birthday, :date add_column :users, :home_address, :text add_column :users, :work_address, :text add_column :users, :position, :string add_column :users, :company, :string end end </code></pre> <p><strong>EDIT</strong></p> <p>20120511224920_devise_create_users</p> <pre><code>class DeviseCreateUsers &lt; ActiveRecord::Migration def change create_table(:users) do |t| ## Database authenticatable t.string :email, :null =&gt; false, :default =&gt; "" t.string :username, :null =&gt; false, :default =&gt; "" t.string :encrypted_password, :null =&gt; false, :default =&gt; "" ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at ## Rememberable t.datetime :remember_created_at ## Trackable t.integer :sign_in_count, :default =&gt; 0 t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip t.string :last_sign_in_ip ## Encryptable # t.string :password_salt ## Confirmable # t.string :confirmation_token # t.datetime :confirmed_at # t.datetime :confirmation_sent_at # t.string :unconfirmed_email # Only if using reconfirmable ## Lockable # t.integer :failed_attempts, :default =&gt; 0 # Only if lock strategy is :failed_attempts # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at ## Token authenticatable # t.string :authentication_token t.timestamps end add_index :users, :email, :unique =&gt; true add_index :users, :reset_password_token, :unique =&gt; true # add_index :users, :confirmation_token, :unique =&gt; true # add_index :users, :unlock_token, :unique =&gt; true # add_index :users, :authentication_token, :unique =&gt; true end end </code></pre> <p>20120619023856_add_name_to_users</p> <pre><code>class AddNameToUsers &lt; ActiveRecord::Migration def change add_column :users, :first_name, :string add_column :users, :last_name, :string end end </code></pre> <p>20121031174720_add_details_to_users.rb</p> <pre><code>class AddDetailsToUsers &lt; ActiveRecord::Migration def change add_column :users, :home_phone, :decimal add_column :users, :cell_phone, :decimal add_column :users, :work_phone, :decimal add_column :users, :birthday, :date add_column :users, :home_address, :text add_column :users, :work_address, :text add_column :users, :position, :string add_column :users, :company, :string end end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload