0

I'm getting this error message when I run the above code generator: (I'm just a beginner)

invoke active_record
Another migration is already named create_posts.....
Use --force to remove the old migration file

What do I type into the terminal window to "use force"

Kara
  • 6,115
  • 16
  • 50
  • 57
user3502289
  • 5
  • 1
  • 3

4 Answers4

2

You are getting the following error because you already have a migration named create_posts in your rails application.

invoke active_record Another migration is already named create_posts..... Use --force to remove the old migration file

So, what you need here is first remove the existing migration and then generate the scaffold.

rails d migration create_posts 
rails generate scaffold post title:string body:text

Or

You could generate the scaffold using --force option

rails generate scaffold post title:string body:text --force

EDIT

As per your comment:

I did that and then a whole bunch of code appears with the lines of code sating invoke...exist...identical.

It means that you already ran a scaffold once for Post successfully and you are trying to generate the scaffold again.

I am not sure why you are doing that BUT identical is not an error. Its just that Rails is telling you that you already have a particular file so I am not creating again.

Kirti Thorat
  • 52,578
  • 9
  • 101
  • 108
0

You can reset your database if you don't care about losing your database with this :

b rake db:reset

This will re-reun all your migrations. But take note! Your migrations should be able to run from one end to the other. So if something is "not working" with the regular rake db:migrate, then you should resolve that issue is specifically.

Show me a more descriptive error, and I can tell you more.

Trip
  • 26,756
  • 46
  • 158
  • 277
  • hi thanks! I tried that and this is what i got: You have 3 pending migrations: 20140405194007 CreatePosts 20140405194222 CreateComments and 20140405195902 CreateComments. How do I get rid of everything and just start over? thanks for your help! Oh, and then it says Run rake db:migrate to update your database and try again. – user3502289 Apr 05 '14 at 22:20
0

You should add other migration in order to change your Post table as you want it to be. Your could begin with rails g migration and see the help provided.

If you want to get away with it you can delete the migration that created the Post table (but I guess you would need to delete the DB)

zrac
  • 153
  • 7
  • how do i delete the whole db and start over? My assignment was to build a blog and so I have I did $rails new blog and then had to run some code generators..I think that is where I got stuck: I put in :$rails generate scaffold post title:string body:text and also $rails generate scaffold comment post_id:integer body:text – user3502289 Apr 05 '14 at 22:26
  • You can delete `development.sqlite3` under `db` dir. You may as well delete all migrations and then execute the generators commands (`rails g scaffold post title:string body:text`, etc). Then execute `rake db:migrate`. Later, you will learn you should edit migrations and not delete them. But for now, beginning, it's just fine to mess do this, I guess (and I did it were I first started). – zrac Apr 05 '14 at 22:37
0

After the first time you generate a scaffold, by default Rails will not overwrite the existing scaffold. This is to ensure that you don't accidentally destroy a lot of work.

If you're really sure you want to regenerate the scaffold and delete any changes you might have made to any of the generated files, try:

rails generate scaffold post title:string body:text --force
Lencho Reyes
  • 359
  • 3
  • 10
  • ok thanks. I did that and then a whole bunch of code appears with the lines of code sating invoke...exist...identical. However, I tried the rails generate scaffold... code again and the same error appeared. – user3502289 Apr 05 '14 at 22:35
  • Yes, the generate scaffold prints quite a few lines. I'm not sure what you mean when you say the same error appears. Could you post the exact sequence of commands you're running with the intervening output, including error messages? You may have to add it to your question as the comment field doesn't allow many characters. – Lencho Reyes Apr 06 '14 at 03:31