# Railsapp/db/migrate Newbie question

**URL:** <https://www.ruby-forum.com/t/railsapp-db-migrate-newbie-question/98147>\
**Category:** Rails\
**Created:** [July 12, 2006, 7:21pm UTC](https://www.ruby-forum.com/t/railsapp-db-migrate-newbie-question/98147 "2006-07-12T19:21:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [July 12, 2006, 7:21pm UTC](https://www.ruby-forum.com/t/railsapp-db-migrate-newbie-question/98147/1 "2006-07-12T19:21:46Z")

</div>

I made a mistake when making my first app. I did not use the:  
ruby script/generate model

method for creating my models. I more or less hand crafted each og  
them. Is there a way to go back so I get my db migration scripts to  
populate?

---

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [July 12, 2006, 8:06pm UTC](https://www.ruby-forum.com/t/railsapp-db-migrate-newbie-question/98147/2 "2006-07-12T20:06:49Z")

</div>

“Joe C.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in  
message news:removed\_email\_address@domain.invalid…

> I made a mistake when making my first app. I did not use the:  
> ruby script/generate model
> 
> method for creating my models. I more or less hand crafted each og  
> them. Is there a way to go back so I get my db migration scripts to  
> populate?
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

just run script/generate model . I’m pretty sure the  
generator  
won’t over-write existing files, so you’ll get test and migration files  
generated. Before you do, make a backup/commit your work - just in case  
🙂

if that doesn’t work, I’d just copy your model files outside of the  
models  
directory, run script/generate model and then copy the model files back

hth

---

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [July 12, 2006, 8:09pm UTC](https://www.ruby-forum.com/t/railsapp-db-migrate-newbie-question/98147/3 "2006-07-12T20:09:42Z")

</div>

> just run script/generate model . I’m pretty sure the  
> generator  
> won’t over-write existing files, so you’ll get test and migration files  
> generated. Before you do, make a backup/commit your work - just in case  
> 🙂
> 
> if that doesn’t work, I’d just copy your model files outside of the  
> models  
> directory, run script/generate model and then copy the model files back
> 
> hth

That’s what I was doing, thanks! Just wanted to make sure there wasn’t  
a simple® way via rake or something.

---

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [July 13, 2006, 3:12pm UTC](https://www.ruby-forum.com/t/railsapp-db-migrate-newbie-question/98147/4 "2006-07-13T15:12:55Z")

</div>

Alan F. wrote:

> Joe C. wrote:
> 
> > what I was doing, thanks! Just wanted to make sure there wasn’t  
> > a simple® way via rake or something.
> 
> You could also leave the models and use ‘script/generate migration’  
> There doesn’t need to be a one-to-one from model to migration.
> 
> A.

thanks!

Here’s a follow-up questionon on models and tables:

Should I keep a one for one correspondence of models to tables? For  
example, I have a couple of tables that I chose not to model - should I  
set up a very small model for those tables as placeholders?

---

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [July 13, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/railsapp-db-migrate-newbie-question/98147/5 "2006-07-13T18:13:43Z")

</div>

If you want to access a table through ActiveRecord methods, you need to  
have a model. So the answer is almost certainly yes.

Mind you, a model doesn’t have to have anything in it. A “blank” model  
like

class Widget \< ActiveRecord::Base  
end

is sufficient to be able to work with all the fields in your table via  
ActiveRecord. It is also necessary.

Joe C. wrote:

> Alan F. wrote:
> 
> > Joe C. wrote:
> > 
> > > what I was doing, thanks! Just wanted to make sure there wasn’t  
> > > a simple® way via rake or something.
> > 
> > You could also leave the models and use ‘script/generate migration’  
> > There doesn’t need to be a one-to-one from model to migration.
> > 
> > A.
> 
> thanks!
> 
> Here’s a follow-up questionon on models and tables:
> 
> Should I keep a one for one correspondence of models to tables? For  
> example, I have a couple of tables that I chose not to model - should I  
> set up a very small model for those tables as placeholders?

---

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [July 13, 2006, 2:20pm UTC](https://www.ruby-forum.com/t/railsapp-db-migrate-newbie-question/98147/6 "2006-07-13T14:20:27Z")

</div>

Joe C. wrote:

> what I was doing, thanks! Just wanted to make sure there wasn’t  
> a simple® way via rake or something.

You could also leave the models and use ‘script/generate migration’  
There doesn’t need to be a one-to-one from model to migration.

A.
