On Saturday, February 1, 2014 8:41:48 PM UTC-6, Bizt wrote:
>
> Hi,
>
> I accidentally created a model with "rails generate model Category" (also 
> creating migrate file) where I didn't specify any fields. Then I run rake 
> db:migrate to create the new table. Upon realising what I'd done, I run 
> "rails destroy model Category". Then I run "rails generate model Category 
> name:string user_id:integer" which created all the new files. Ofcourse now 
> db:migrate wouldn't work coz I forgot I'd created the category table prior. 
> So, I thought I'd remove the old table and run rake db:reset. This appeared 
> to create all the tales again, but it keeps creating the OLD category table 
> - the one without any fields. I've tried dropping the database, destroying 
> the model/ migrate files, rolling back the migration, db:shema:load/ 
> db:create:all/ . But every time, even if there is no "create category 
> table" migrate file - it still creates the category table with no fields.
>
> Is this normal? I don't know where it's getting the schema from but it 
> can't be reading only from my db:migrate files. Does it get them from log 
> files when recreating the db, or does it look directly at the db and 
> rebuild. I want my database build purely from the files I'm looking at in 
> my db/migrate folder. How do I do this?
>

Try generating your model and then adding a 'drop_table' command to your 
migration. 

drop_table :categories if self.table_exists?("categories")
    
create_table :categories do |t| ......


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/ac284fda-fa41-41d1-8cbb-5725fd6e62b2%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to