Question

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"

Was it helpful?

Solution

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.

OTHER TIPS

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.

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)

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top