[Ruby] [In team development] Error when moving to another member’s branch and doing rails s [Rails]

1 minute read

Reference target person

  • Team development beginner
  • Those who are troubled with database related errors in application development with Rails
  • Git newbie

environment

$ rails -v
Rails 6.0.3.1
$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]
$ git --version
git version 2.27.0
$ mysql --version
mysql Ver 14.14 Distrib 5.7.29, for osx10.15 (x86_64) using EditLine wrapper

Situation

  • I wanted to move to another member’s branch and check the behavior for review, but I got an error when starting the server.
  • Apparently it’s a database related error.

ActiveRecord::PendingMigrationError

https://qiita.com/KONTA2019/items/0444ae3b8c8936a56ee0

Resolve by referring to the above. By the way, I

$ rails db:migrate

Solved by.

But then I got the following error: .. ..

Multiple migrations have the name ~~~.

In conclusion, ~~~ contains migration file name.

In the case of I,

Multiple migrations have the name CreateUsers.

Then, when I check my migration file,

$ rails db:migrate:status

 Status Migration ID Migration Name
- -------------------------------------------------
   up 20200618162841 Create tweet posts
   up 20200620004226 Change tweetposts to tweets
  down 20200621075518 Create posts
  down 20200623102444 Change posts to chats
  down 20200627042358 Create users
   up 20200627080839 Create users
   up 20200627083356 Add column to users
  down 20200627220915 Change datatype content of chats
   up 20200703201452 ********** NO FILE **********
  down 20200710035709 Add user id to tweets

Yes, there is a CreateUsers file.

As you can see, it is possible to guess from the content of the error statement that “** There is a migration file with the same name, so I do not know which one should be used for database construction **” I can do it.

So down 20200627042358 Create users Delete this file,

$ rails db:migrate
$ bundle exec rails s

Now you can start the server!

By the way,…

In the migration file, up 20200703201452 ********** NO FILE **********

You’re curious? ?

This is a mysterious phenomenon of building a database with reference to a file that does not exist, so I would like to delete it.

The cause of this is caused by deleting the migration file before downing the migration, but the solution is below.

https://qiita.com/beanbeenzou/items/e8886071ab1e1cf7a9c0