最近我处理的数据库问题阻止我运行我的rails应用程序。每当我的应用收到请求时,我都会收到以下错误:
ActiveRecord::PendingMigrationError (
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=development
):
我的迁移已经运行,但我仍尝试迁移以解决问题。当我这样做时,我收到了这个错误:
PG::DuplicateTable: ERROR: relation "users" already exists
看来Rails正在尝试运行已经运行的迁移!我尝试检查迁移状态,看看是否可以解决问题。结果如下:
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
正如您在此处所看到的,似乎有许多迁移错过了他们的文件。我不记得删除任何迁移,当然不是这么多!此外,我们发现所有可识别的迁移(包含其文件的迁移)尚未运行。这几乎就好像迁移都被重命名一样,保留了他们的更改,而他们自己似乎没有运行,但同样没有发生这样的事件。
到目前为止,我已经受够了。看到数据库中的数据主要来自种子文件,我决定只是擦除它并重新开始:
rails db:drop
rails db:create
rails db:migrate
但是,当我运行db:migrate时遇到了同样的问题。事实上,好像什么都没有改变。救命啊!
答案 0 :(得分:2)
您的up
似乎指向不同Rails应用程序的数据库,这就是为什么您会看到一组完全不相关的状态为output
的迁移时间戳。