我无法通过终端和RoR 在我的数据库中迁移新列。 我只迈出了第一步:
**$ rails g migration add_online_to_posts online:boolean**
Running via Spring preloader in process 13406
invoke active_record
create db/migrate/20170808141302_add_online_to_posts.rb
之后没有任何作用:
**$ rails db:migrate**
rails aborted!
ActiveRecord::DuplicateMigrationVersionError:
Multiple migrations have the version number 20170725122210.
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:1257:in `validate'
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:1123:in `initialize'
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:1007:in `new'
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:1007:in `up'
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:985:in `migrate'
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/home/projets/RoR_formation/vendor/bundle/gems/railties-5.1.2/lib/rails/commands/rake/rake_command.rb:21:in `block in perform'
/home/projets/RoR_formation/vendor/bundle/gems/railties-5.1.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/home/projets/RoR_formation/vendor/bundle/gems/railties-5.1.2/lib/rails/command.rb:46:in `invoke'
/home/projets/RoR_formation/vendor/bundle/gems/railties-5.1.2/lib/rails/commands.rb:16:in `<top (required)>'
/home/projets/RoR_formation/bin/rails:9:in `require'
/home/projets/RoR_formation/bin/rails:9:in `<top (required)>'
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
/home/projets/RoR_formation/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate
我可以通过IDE处理列:
但是当我这样做时:
**$ Status Migration ID Migration Name**
up 20170725122210 Create posts table
up 20170726082500 Rename post title to intitule
up 20170728143925 Create categories
up 20170807110617 ********** NO FILE **********
down 20170808113533 Add slug to posts
答案 0 :(得分:0)
您已经使用前缀20170725122210
运行迁移(看起来您可能也删除了它)。要进行快速修复,请将最新迁移更改为20170725122211
(或您的架构迁移表中不包含的任何其他数字)。您可能还想运行rails db:schema:dump
并检查db/schema.rb
的输出,以查找迁移中不存在的表。