问题
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