获取:“迁移正在等待;运行'bin / rake db:migrate RAILS_ENV = development'以解决此问题。”克隆和迁移项目后

时间:2014-01-23 13:43:32

标签: ruby-on-rails ruby-on-rails-4 dbmigrate

我克隆了我的项目。捆绑“捆绑安装”,然后运行“rake db:migrate”。我收到此错误:(当我运行rails服务器并将我的浏览器打开到localhost:3000时)“迁移正在等待;运行'bin / rake db:migrate RAILS_ENV = development'以解决此问题。”

我逐个检查了所有迁移,并且所有迁移都没有错误地执行。执行“rake db:migrate”后也没有显示错误。

这是我在执行“rake db:migrate:status

时看到的内容

我在开发环境中。如果您需要任何其他信息,请与我们联系。

我还尝试过“捆绑exec rake db:migrate”,并将“捆绑exec rake db:migrate:reset”改为“burninggramma”。

任何导致错误的线索?

15 个答案:

答案 0 :(得分:22)

有趣。你运行了 rake db:create 吗?假设您使用的是sqlite3,请执行以下操作:

      rm -f db/*.sqlite3
      rake db:create
      RAILS_ENV=development rake db:migrate
      rails s -e development

另外,您是否可以列出 config / database.yml 文件的内容?

修改:警告!显然,您将丢失现有数据。

答案 1 :(得分:14)

运行migrate命令后,我仍然遇到同样的错误。

对我来说有用的就是停止rails服务器并重新启动它。

答案 2 :(得分:6)

使用rake db:migrate:status列出已执行的迁移,并查看是否已执行每次迁移。您可以尝试使用rake db:abort_if_pending_migrations取消迁移,然后尝试再次迁移。

答案 3 :(得分:4)

1.也许是ruby2 / rails4中的默认值,但您尝试过:bundle exec rake db:migrate

2.另一种选择是重置整个数据库 - 小心使用!重置所有数据 - bundle exec rake db:migrate:reset

+)我只是确保你在同一个开发环境中执行所有内容:

RAILS_ENV=development bundle exec rake db:migrate:reset
RAILS_ENV=development bundle exec rails s

答案 4 :(得分:4)

正在运行rake db:migrate RAILS_ENV=test为我做了

答案 5 :(得分:1)

打开数据库,然后单击schema_migration表。迁移将在下面列出。 enter image description here

对版本列进行排序,然后找到要返回的最新迁移。删除或插入一个新的。 Rails将所有迁移历史记录保留在此表中,因此您可以根据自己的喜好调整迁移历史记录。

答案 6 :(得分:0)

这对我有用:     -gem install rails -v 4.1.0 内部Gemfile:     -gem'rail','4.1.0' (用这个替换更新/更旧) 捆绑安装和更新    -bundle安装    -bundle更新 在你的application.rb中: 删除/评论 - config.active_record.raise_in_transactional_callbacks = true

运行捆绑rake:    -bundle exec rake db:migrate 刷新页面,错误应该消失。

答案 7 :(得分:0)

“db:migrate:reset”这两个原因对我不起作用

1) loosing data 
2) we moved from php to rails, so we had an existing DB and the migrations were written on top of it not from the scratch

所以我尝试的是更新'scheema_migrations'(mysql)表,其中包含我确实已经在我的db(开发)上运行的迁移列表(只是版本值),这可能是耗时的过程但它的确有效。我不打算在制作上尝试这个。

答案 8 :(得分:0)

猜测 错误是你正在创建一个已经存在的表,我以前遇到过这个问题。 第1步 rake dv:migrate

时查看错误

第2步 转到创建此表的模型

第3步 在create_table:[YOUR TABLE]

之前添加drop_table:[YOUR TABLE]

第2步 运行rake db:migrate

第3步 迁移完成后删除drop_table

答案 9 :(得分:0)

我遇到了这个问题,这是因为我的rails文件放在了一个名为“ [rails]”的文件夹中。似乎rake不喜欢文件夹名称中使用以下符号“ []”。

希望这对其他人有帮助。

答案 10 :(得分:0)

了解足够危险的 Rails教程中,我遇到了相同的错误。我在Windows 10计算机上使用Git Bash终端。在尝试使用命令(在另一个终端中)迁移数据库之后,该错误显示在我正在运行警卫的终端中:

$ bundle exec rake db: migrate:

尝试@lewstherin提供的解决方案后,我仍然遇到相同的错误。我尝试了以下命令:

$ rails test 并得到了明确而有用的警告:

Migrations are pending. To resolve this issue, run:

bin/rails db:migrate RAILS_ENV=test

我运行了命令:

$ bin/rails db:migrate RAILS_ENV=test

现在我又在工作。

答案 11 :(得分:0)

我在genieacs中遇到了同样的问题,这段代码有所帮助:

rake db:drop rake db:create rake db:schema:load RAILS_ENV=development
rake db:migrate rails s -e development

答案 12 :(得分:0)

对我来说,我只需要迁移即可解决错误:

import React from 'react'
import { View, Text, StyleSheet,TouchableOpacity } from 'react-native'
//import { TouchableOpacity } from 'react-native-gesture-handler'
import { Icon } from 'react-native-vector-icons/FontAwesome';

const userMain = () => {
    return (
        <View style={styles.container}>
            <Text>user homepage here</Text>
            <TouchableOpacity style={styles.btn}>
                <Text style={styles.btnText}> Text </Text> 
            </TouchableOpacity>
        </View>
    )
}
const styles = StyleSheet.create({
    container: {
        position:'relative',
        alignItems: 'center',
        flex: 1,
        justifyContent: 'center',
    },
    btn: {
        width: null, height:null, zIndex: 0, position: 'absolute',  top: 0, bottom:0, left:0, right:0
    },
    btnText: {
        fontSize: 50,
        color: 'black',
        zIndex:99
    }

})

export default userMain

通过在rake db:migrate --trace 中将false设置为config.active_record.migration_error可能使它可行,但我不建议这样做。

答案 13 :(得分:-2)

您始终可以运行rake db:reset

答案 14 :(得分:-2)

当我执行rake test并遇到错误时:

  

&#34;耙子中止了! ActiveRecord :: PendingMigrationError:迁移是   悬而未决。要解决此问题,请运行:bin / rake db:migrate   RAILS_ENV =测试&#34;

我尝试并成功:

rm -f db/*.sqlite3

rake db:create

RAILS_ENV=development rake db:migrate

rails s -e development