简体   繁体   中英

Rails Migration Successful, But Not Showing up in Model?

I can't figure out why my migration worked but doesn't show up in corresponding model...

  1. Ran a migration to add field to a table:

     def up add_column :quick_tests, :trace_route_data, :text, :null => true end def down remove_column :quick_tests, :trace_route_data end 
  2. Looked in schema.rb , and it's there.

  3. Added :trace_route_data to attr_accessible in QuickTest model

  4. Opened up rails console by doing bundle exec rails c , ran QuickTest.new and I can see the :trace_route_data field.

But, when I execute the same QuickTest.new statement when paused in the QuickTestController#show method, the field isn't there.

Why is this field showing up in the rails console but not my actual app??

I suspect something went wrong during the migration such that it never got applied to the database. Rails uses the actual schema in the database to build model objects, so the fact that your model doesn't show the change means the change is almost certainly not in the database (despite being in the schema.rb ).

I'd recommend you rollback your migration and run it again in verbose mode. This should either show you the error, or at least show you the SQL being run. In that case, you can run the SQL manually at the db console and see what happens then.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM