What's the syntax for dropping a database table column through a Rails migration?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- NOT DISTINCT query in mySQL
- Eager-loading association count with Arel (Rails 3
- Flush single app django 1.9
相关文章
- Ruby using wrong version of openssl
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
For older versions of Rails
For Rails 3 and up
To remove the column from table you have to run following migration:
Then run command:
in rails 5 you can use this command in the terminal:
for example to remove the column access_level(string) from table users:
and then run:
Generate a migration to remove a column such that if it is migrated (
rake db:migrate
), it should drop the column. And it should add column back if this migration is rollbacked (rake db:rollback
).The syntax:
remove_column :table_name, :column_name, :type
Example:
Note: If you skip the data_type, the migration will remove the column successfully but if you rollback the migration it will error.
You can try the following:
(Official documentation)