11

I use

rails generate model mynewmodel string:name string:description

to generate a new model. How do I deploy this new model to my develop databse ? I already have a bunch of databases in my sqlite db.

I have tried

rake db:migrate

it seemed having trouble to generate this new table in db.

update: added error message

==  CreateMynewmodels: migrating ===============================================
-- create_table(:mynewmodels)
rake aborted!
An error has occurred, this and all later migrations canceled:

undefined method `name' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x3ad5c50>

Tasks: TOP => db:migrate

Thanks

4
  • What you're doing is correct (rake db:migrate). We can't help without seeing error messages. Commented Nov 20, 2012 at 22:10
  • Did you run rake db:create first? Commented Nov 20, 2012 at 22:13
  • @Casper no, i should run db:create before db:migrate? Commented Nov 20, 2012 at 22:13
  • Here's a good guide: guides.rubyonrails.org/getting_started.html Commented Nov 20, 2012 at 22:14

4 Answers 4

16

The order of your fieldname:type combo is incorrect. Try

rails generate model mynewmodel name:string description:string
Sign up to request clarification or add additional context in comments.

1 Comment

WOw. All of you were in a race apparently to answer this question. You WON!
4

The error in rails generate model mynewmodel string:name string:description

You should swap string and name

rails generate model mynewmodel name:string description:string

Comments

3

Use name:string instead of string:name same for description

Comments

0

Great article for advanced usage: Advanced Rails model generators

Pay attention that you have to wrap parameter price:decimal{10,2} to quotes. It's vital and you may have incorrect behavior of generator if you don't do it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.