2017-08-08 103 views
0

我無法通過終端和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處理列: enter image description here

但是當我做:

**$ 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

你是如何創建你的遷移文件的?您是使用生成器還是複製和編輯遷移文件?遷移文件必須是唯一版本。 – MarsAtomic

+0

的確是我通過終端使用了一臺發電機。但是對於本教程的步驟,我手動刪除了文件( – Kriss

回答

0

您已經使用pre修復20170725122210(它看起來像你可能也刪除了它)。爲了快速修復,請將您的最新遷移更改爲20170725122211(或任何其他不在您的模式遷移表中的數字)。您可能還想運行rails db:schema:dump並檢查db/schema.rb的輸出,以查找遷移中不存在的表。

+0

),實際上我通過終端使用了一個生成器。但是對於本教程的步驟,我手動刪除了文件。當我運行** rails db:schema:dump **時,它什麼都不做。 。因此我無法檢查db/schema.rb的輸出。我將我的最新遷移重構爲20170725122211我還通知Rubymine允許運行並從IDE創建數據庫遷移。我可以使用這個選項嗎? – Kriss