Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 挂起迁移错误|无法删除重复迁移_Ruby On Rails_Ruby_Terminal - Fatal编程技术网

Ruby on rails 挂起迁移错误|无法删除重复迁移

Ruby on rails 挂起迁移错误|无法删除重复迁移,ruby-on-rails,ruby,terminal,Ruby On Rails,Ruby,Terminal,我正在尝试运行rails服务器,遇到以下错误: Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development 所讨论的数据库当前为空,因此不必担心数据丢失。当我运行代码时: bundle exec rake db:migrate RAILS\u ENV=development rake db:migrate rakedb:migrate 返回错误: rake abort

我正在尝试运行rails服务器,遇到以下错误:

Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development
所讨论的数据库当前为空,因此不必担心数据丢失。当我运行代码时:

bundle exec rake db:migrate

RAILS\u ENV=development rake db:migrate

rakedb:migrate

返回错误:

rake aborted!
ActiveRecord::DuplicateMigrationNameError: 

Multiple migrations have the name CreatePosts


Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Started GET "/" for ::1 at 2015-09-22 11:30:34 -0400

ActiveRecord::PendingMigrationError (

Migrations are pending. To resolve this issue, run:

bin/rake db:migrate RAILS_ENV=development

):
运行服务器时,这将返回到我的终端:

rake aborted!
ActiveRecord::DuplicateMigrationNameError: 

Multiple migrations have the name CreatePosts


Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Started GET "/" for ::1 at 2015-09-22 11:30:34 -0400

ActiveRecord::PendingMigrationError (

Migrations are pending. To resolve this issue, run:

bin/rake db:migrate RAILS_ENV=development

):
最后,运行
rakedb:migrate:status
返回:

Schema migrations table does not exist yet.
可能发生了什么?非常感谢您的帮助


bin/rake
命令之后的
migrate:status
输出

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20150922142819  Devise create users
   up     20150922143253  Create posts
  down    20150922143414  Create posts
  down    20150922145906  Acts as votable migration
  down    20150922150209  Create comments
  down    20150922151035  Acts as follower migration

在运行迁移之前,必须创建数据库架构/结构
db:schema:load
将为您执行以下操作:

bin/rake db:schema:load

至于错误“多次迁移的名称为CreatePosts”,正如它所说的那样。在您的
db/migrate
文件夹的内容中查找文件中具有相同名称的两个文件
class CreatePosts
——它们的名称应不同,或者如果第二个文件重复,则应删除它们。

看起来您有多个同名迁移。这是不允许的。如果您的数据库是空的,没有表,最好的方案是重命名第二个表,这样它们就不会再冲突了

显然,文件名是唯一的,但是每个迁移文件都定义了一个类,这些类也必须是唯一的,并且应该与文件名匹配

拥有
201509201949343_create_posts
201509220293910_create_posts
将是这里的典型冲突


您可能想调查这是如何实现的,因为让您的开发模式与生产模式不同通常是个坏主意。在本地解决冲突后,请尝试在生产环境中相应地更新架构跟踪表。

使用
bin/rake
命令,更新问题以显示该问题的输出。@ether
bin/rake
!=
bin/rake db:schema:load
-您说您的数据库是空的,您必须加载它。我确实使用了整个代码,只是将其称为
bin/rake
@以太,但您显示的输出不是
db:schema:load
命令。我还需要等待吗?从migrate文件夹中删除DUP后,我再次运行了
rake db:migrate
,它以
关闭
状态完成了文件的迁移。谢谢你的帮助!我想你的项目中有重复的迁移文件,你能给我们看一下迁移目录文件吗?我想我可能在创建时复制了它们,我能安全地删除第二个吗?首先要确定的是它们是否相同,或者它们的名称是否一致。在您的迁移文件中搜索
CreatePosts
,您会很快找到它们。它们完全相同,我删除了副本。我仍然有3次迁移,状态为
down
?您说的是从头开始的迁移,完全没有表,还是针对现有的模式?你说的地位是什么意思
rakedb:migrate
应该会把你带上来。