Neither migrations nor loading schema adds a column to Rails/MySQL database

﹥>﹥吖頭↗ 提交于 2019-12-11 07:32:22

问题


I've created a migration to add an is_ms_admin column to my MySQL database in Rails:

class AddIsAdminToUsers < ActiveRecord::Migration
  def change
    add_column :users, :is_ms_admin, :boolean
  end
end

This has correspondingly updated the schema:

create_table "users", force: :cascade do |t|
  t.string   "email",                  limit: 255, default: "", null: false
  t.string   "encrypted_password",     limit: 255, default: "", null: false
  t.datetime "remember_created_at"
  t.integer  "sign_in_count",          limit: 4,   default: 0,  null: false
  t.datetime "current_sign_in_at"
  t.datetime "last_sign_in_at"
  t.string   "current_sign_in_ip",     limit: 255
  t.string   "last_sign_in_ip",        limit: 255
  t.datetime "created_at"
  t.datetime "updated_at"
  t.boolean  "is_approved"
  t.string   "reset_password_token",   limit: 255
  t.datetime "reset_password_sent_at"
  t.boolean  "is_ms_admin"
end

On running rake db:migrate, the migration runs without throwing any errors. Using rake db:schema:load is also error-free. Both appear to be successful.

When I select the column names from the MySQL table, however, only most of the columns exist:

mysql> SELECT `COLUMN_NAME` 
    -> FROM `INFORMATION_SCHEMA`.`COLUMNS` 
    -> WHERE `TABLE_SCHEMA`='metasmoke' 
    ->     AND `TABLE_NAME`='users';
+---------------------+
| COLUMN_NAME         |
+---------------------+
| id                  |
| email               |
| encrypted_password  |
| remember_created_at |
| sign_in_count       |
| current_sign_in_at  |
| last_sign_in_at     |
| current_sign_in_ip  |
| last_sign_in_ip     |
| created_at          |
| updated_at          |
| is_approved         |
+---------------------+

I'm primarily concerned with the is_ms_admin column, but it would also be useful to know why the two reset_password columns don't exist.

I'm not running all this from the Rails console, so the issue is not because the console has cached things; having reloaded the INFORMATION_SCHEMA table too, it's apparent that the columns aren't created at all, rather than being any surrounding issue.

Why does the column not exist, and how can I fix it?

来源:https://stackoverflow.com/questions/36093961/neither-migrations-nor-loading-schema-adds-a-column-to-rails-mysql-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!