简体   繁体   中英

Rails believes there are pending migrations

Recently I've dealing with a database issue that prevents me from running my rails app. I get the following error whenever my app receives a request:

ActiveRecord::PendingMigrationError (

Migrations are pending. To resolve this issue, run:

    bin/rails db:migrate RAILS_ENV=development

):

My migrations have already been run, but I tried to migrate anyway to solve the problem. When I did, I got this error:

PG::DuplicateTable: ERROR:  relation "users" already exists

It appears that Rails is trying to run migrations that have already been run! I tried checking the migration status to see if that could shed any light on the issue. Here is the result:

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20160927153148  ********** NO FILE **********
   up     20161004160131  ********** NO FILE **********
   up     20161005125752  ********** NO FILE **********
   up     20161011181504  ********** NO FILE **********
   up     20161014135001  ********** NO FILE **********
   up     20161014140631  ********** NO FILE **********
   up     20161014143818  ********** NO FILE **********
   up     20161014144342  ********** NO FILE **********
   up     20161014144530  ********** NO FILE **********
   up     20161014144742  ********** NO FILE **********
   up     20161014145130  ********** NO FILE **********
   up     20161014164935  ********** NO FILE **********
   up     20161014164936  ********** NO FILE **********
   up     20161014201553  ********** NO FILE **********
   up     20161017190913  ********** NO FILE **********
   up     20161018131458  ********** NO FILE **********
   up     20161018180142  ********** NO FILE **********
   up     20161020182715  ********** NO FILE **********
   up     20161023171522  ********** NO FILE **********
   up     20161027202306  ********** NO FILE **********
   up     20161107160642  ********** NO FILE **********
   up     20161107185720  ********** NO FILE **********
   up     20161108204903  ********** NO FILE **********
   up     20161115174824  ********** NO FILE **********
   up     20161121201101  ********** NO FILE **********
   up     20161122205308  ********** NO FILE **********
   up     20170208132901  ********** NO FILE **********
   up     20170208183331  ********** NO FILE **********
   up     20170209204508  ********** NO FILE **********
   up     20170220164639  ********** NO FILE **********
   up     20170301174731  ********** NO FILE **********
   up     20170302174721  ********** NO FILE **********
  down    20170913142804  Create users
  down    20170913153749  Add devise to users
  down    20170913182252  Create clients
  down    20170913183734  Create addresses
  down    20170919131420  Update user table
  down    20170919150013  Split address type
  down    20170919151010  Remove auth tier from user
  down    20170919170757  Remove requirement from extended
  down    20170921135056  Create client configurations
  down    20170922145446  Drop zips
  down    20170924220818  Create groups
  down    20170924232318  Create permissions
  down    20170926132737  Create overrides
  down    20171003185617  Create client groups
  down    20171003201301  Update address table
  down    20171003202611  Create locations
  down    20171004143859  Create clients users
  down    20171005161331  Add avatar to users
  down    20171005163530  Create sites
  down    20171107191612  Add deleted at to tables
  down    20171110205840  Add is public to sites
  down    20171115190716  Add superuser to users
  down    20171117153515  Create versions
  down    20171117153516  Add object changes to versions
  down    20171211154208  Create roles
  down    20171211154807  Add roles to users
  down    20171211161939  Remove superuser from users
  down    20171211163226  Add descriptions to roles
  down    20171211190243  Rename scope on roles
  down    20171218173758  Devise invitable add to users
  down    20171218192514  Add invitation domain to users

As you can see here, it appears that there are a number of migrations missing their files. I do not recall deleting any migrations, and certainly not this many! Additionally, we see that all the recognizable migrations, the ones with their files, have not been run. It's almost as if the migrations were all renamed, leaving their changes intact, while they themselves appear to not have run, but again, no such event occurred.

By this point, I'd had enough of the issue. Seeing as the data in the database was mostly from a seed file, I decide just to wipe it and start over:

rails db:drop
rails db:create
rails db:migrate

However, I ran into the same issue when I ran db:migrate. In fact, it seems as though nothing has changed. Help!

您的database.yml似乎指向其他Rails应用程序的数据库,这就是为什么您看到一组完全不相关的迁移时间戳,并且它们的状态为up

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM