简体   繁体   中英

Modify schema.rb in rails application

I am new to rails.

I want to create an Article model. So I run,

rails g model Article name:string context:string

Instead of content I type in context , Is there a way to update the schema.rb file that gets generated?

I would like the articles table to have name and content columns.

Don't focus on schema.rb -- this is just a dump of the current state of your database. Instead, what you need to do is correct the migration file. It is the migration files that actually define what tables/column will exist in production in the end so they must be correct. I'd recommend:

  1. Run ls -ltr db/migrate -- use this to find your migration file and copy the date string. Rails uses this as the "version" of the migration. For example: "20140809165359_create_articles", the version is "20140809165359".
  2. Run bundle exec rake db:migrate:down VERSION=20140809165359 (replace the version number with your own, here)
  3. Now go fix your migration file (change "context" to "content")
  4. Run bundle exec rake db:migrate to migrate back up.

This will fix the underlying problem and you'll notice that now, after migrating back up, your schema.rb will be fixed too.

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